Ren'Py Add a blur on menu choice and in the menus

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
Hello everybody,

I am ashamed to ask a question again but I can't find an answer that suits me.

I working on my Renpy Gui and i want to add a blur of a current image scene when a menu choice is comming and when the player goes to the menu. (for the menu, same image than the current scene but with a blur and why not a little bit of translucent black (on photoshop i using a black square with 30% opacity.)

Thank you very much.
 

Playstorepers

Member
May 24, 2020
160
79


U can check out this thread and replace your image in the menu with the blurred picture.
I don't think an actual blur effect exists within renpy.
 
  • Like
Reactions: UncleNanard

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
Hello thanks for your answer i already found the link, but the date is 2011. I think the latest version of renpy can do the blur.

I you want to try, the game Wicked Paradise use this fonction, but i don't understand how.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
RenPy does have a blur, though I'm not sure if it helps you in this circumstance.

For example...
image my_blur_img = im.Blur("pic2.webp", 1.5)

Using , that take an existing image and transform it somehow.

There are lots of other options. Personally, I use and a fair amount.

My understanding though is that the sort of blur you are aiming for is done sort of automatically by RenPy when you invoke screen game_menu(). But like you, I can't figure out how. When I just tried it with my test script, I ended up with a black background instead. Pale Carnations is another game that shows menus and popup panels over the of the existing scene, slightly blurring the background while the overlay is showing. I'll try to return to this over the weekend, if nobody offers a better solution before then... time permitting.
 

Radnor

Member
Game Developer
Nov 9, 2021
365
943
Something like:
Code:
define bg_blur_level=0

init python:
  def tf_bg_blur_fn(tf,st,at):
    global bg_blur_level
    blur_delta=0.5 if renpy.get_screen("choice") else -0.5
    tf.blur=bg_blur_level=max(0,min(10.0,bg_blur_level+blur_delta))
    return 0.01

transform tf_bg_blur:
  function tf_bg_blur_fn

label start:
  $renpy.show_layer_at(tf_bg_blur,camera=True)
  scene bg_image
  "test"
  scene bg_image2 with dissolve
  menu:
    "Option 1":
      pass
    "Option 2":
      pass
    "Option 3":
      pass
  "test 2"
  return
Edited version after anon's post mentioned show_layer_at function.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
I working on my Renpy Gui and i want to add a blur of a current image scene when a menu choice is comming and when the player goes to the menu.
Hmm, what do you mean by "menu choice" ? The menu statement ?
Code:
label whatever:
    scene imageName
    "blabla"
    menu whatever.menu:
        "choice 1":
            "aaa"
        "choice 2":
            "bbb"
You want "imageName" being blurred when the player will hit the "whatever.menu" menu ?


If it's this, then it's not difficult:
Python:
#  Transform blurring the image.
transform withBlur:
    blur 10     # Change the value for the blur factor of your taste.
#  Transform removing the blur.
transform noBlur:
    blur 0

init python:
    #  Intercept the menu call
    def menuEx( items, *args, **kwargs ):
        #  Blur the content of the /master/ layer, that is the layer where
        # the image is displayed by default.
        renpy.show_layer_at( withBlur, layer="master" )
        #  Then ask Ren'Py to display the menu
        return renpy.display_menu( items, *args, **kwargs )

    #  Tell Ren'Py that now the menu have to first pass through your code.
    store.menu = menuEx
In the screen.rpy file, edit the screen "choice" to change it's action:
Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            #  A click on one of the choice will remove the blur, then do what the choice do.
            textbutton i.caption action [ Function( renpy.show_layer_at, noBlur, layer="master" ), i.action ]
And finally, edit the "options.rpy" file, and verify that it contain define config.gl2 = True, else add it.
And it's done. Each time a menu will appear, the background will be automatically blurred.

By appearing order:
Animation and Transformation Language property, variable, function, and finally function.


If you meant something else, then explain what it is.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
image my_blur_img = im.Blur("pic2.webp", 1.5)
Since the 7.4.0, most the Image Manipulators now have an ATL equivalent. Image Manipulators will probably stay, because they can be useful for creator-defined displayable, but the ATL properties are to prefer each time it's possible.

Pros:
  • Probably faster since they rely on OpenGL (or equivalent) API, while the im rely on PyGame computing ;
  • You don't need to declare an image to apply a transform ;
    scene myImage at myTransform
    Code:
    scene myImage:
        transformProperty itsValue
  • You can apply a transform to a layer without having to care what image is displayed ;
    show layer layerName at myTransform

Cons:
Since it rely on Ren'Py's second generation of OpenGL support (GL2), not all players will be able to play your game. config.gl2 being actually the main cause of "lately some Ren'Py games don't works anymore on my computer".


Be noted that if you started your project prior to the 7.4.0, the define config.gl2=True will be missing, and you'll not see the effect during your tests.
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
First of all, thank you to all the people who participated.

Anne :

You are very impressive, it looks so easy for you. I searched for several hours last night, I did a lot of forums and sites and I couldn't find an answer and you manage to do it so fast. Thank you so much.

Hmm, what do you mean by "menu choice" ? The menu statement ?
Yes, and the résult is very good, but do you think it can be blurry + little bit darker ?

You don't have permission to view the spoiler content. Log in or register now.

For the others menus, can you add the blur on all the menu (save, load, prefs, about...) ? :

You don't have permission to view the spoiler content. Log in or register now.

Thanks again to everyone, when someone is a beginner like me, your help is really precious.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
You are very impressive, it looks so easy for you.
It looks so easy because it's years that I search for several hours this or that solution. And sometimes I end up remembering it ;)


Yes, and the résult is very good, but do you think it can be blurry + little bit darker ?
Yes. Nowadays Ren'Py have a full black background by default, therefore if you play with the alpha channel (opacity level) of the image, it will blend with it, what will make it darker :
Python:
transform withBlur:
    blur 10
    alpha 0.8   # Perhaps a bit too dark.
transform noBlur:
    blur 0
    alpha 1.0   # Full opacity. Should not be needed but better safe than sorry.

For the others menus, can you add the blur on all the menu (save, load, prefs, about...) ? :
Hmmm... Yes, and I'm an idiot. There were an even easiest way to do this for the menus.

Just add this in top of each screen you want to have the blur effect
Code:
    on "show" action Function( renpy.show_layer_at, withBlur, layer="master" )
    on "hide" action Function( renpy.show_layer_at, noBlur, layer="master" )
So for the menu a simple:
Code:
screen choice(items):
    on "show" action Function( renpy.show_layer_at, withBlur, layer="master" )
    on "hide" action Function( renpy.show_layer_at, noBlur, layer="master" )

    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action
Would have been enough.
But well, at least the readers have learned a thing or two during the process.


WARNING:
  1. This obviously still need the define config.gl2 = True, with the limitation I talked about above.
  2. The on screen statement is broke on part of the 7.4.x branch. You need at least the version 7.4.9 for this to works.
    I know it, I lost near to 20 minutes trying to figure why it wasn't working, before finally testing with a more recent version.
  3. From the SDK and when the developer mode is enabled, you'll have the checkered background when a screen is displayed. This will give you a false idea of the result. You need to add define config.transparent_tile = False on your code.
    I know it, I lost the following 10 minutes searching for the undocumented configuration value.

So, yeah, as you can see, it's "so easy", but mostly because I know that it should works and that there's an undocumented configuration value somewhere. What mean that I insist until it effectively works, and search until I found.
 
  • Like
Reactions: UncleNanard

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
It looks so easy because it's years that I search for several hours this or that solution. And sometimes I end up remembering it ;)
I hope one day i can have your skill. I know I have made progress in the last 2 months, but I am far from your level.


Yes. Nowadays Ren'Py have a full black background by default, therefore if you play with the alpha channel (opacity level) of the image, it will blend with it, what will make it darker :
Python:
transform withBlur:
    blur 10
    alpha 0.8   # Perhaps a bit too dark.
transform noBlur:
    blur 0
    alpha 1.0   # Full opacity. Should not be needed but better safe than sorry.



Hmmm... Yes, and I'm an idiot. There were an even easiest way to do this for the menus.

Just add this in top of each screen you want to have the blur effect
Code:
    on "show" action Function( renpy.show_layer_at, withBlur, layer="master" )
    on "hide" action Function( renpy.show_layer_at, noBlur, layer="master" )
So for the menu a simple:
Code:
screen choice(items):
    on "show" action Function( renpy.show_layer_at, withBlur, layer="master" )
    on "hide" action Function( renpy.show_layer_at, noBlur, layer="master" )

    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action
Would have been enough.
But well, at least the readers have learned a thing or two during the process.


WARNING:
  1. This obviously still need the define config.gl2 = True, with the limitation I talked about above.
  2. The on screen statement is broke on part of the 7.4.x branch. You need at least the version 7.4.9 for this to works.
    I know it, I lost near to 20 minutes trying to figure why it wasn't working, before finally testing with a more recent version.
  3. From the SDK and when the developer mode is enabled, you'll have the checkered background when a screen is displayed. This will give you a false idea of the result. You need to add define config.transparent_tile = False on your code.
    I know it, I lost the following 10 minutes searching for the undocumented configuration value.

So, yeah, as you can see, it's "so easy", but mostly because I know that it should works and that there's an undocumented configuration value somewhere. What mean that I insist until it effectively works, and search until I found.
I tried to add the alpha lane but i think there is a problem :

You don't have permission to view the spoiler content. Log in or register now.

Thanks again for your help.
 

crabsinthekitchen

Well-Known Member
Apr 28, 2020
1,550
8,806
I hope one day i can have your skill. I know I have made progress in the last 2 months, but I am far from your level.




I tried to add the alpha lane but i think there is a problem :

You don't have permission to view the spoiler content. Log in or register now.

Thanks again for your help.
did you try this?
From the SDK and when the developer mode is enabled, you'll have the checkered background when a screen is displayed. This will give you a false idea of the result. You need to add define config.transparent_tile = False on your code.
I know it, I lost the following 10 minutes searching for the undocumented configuration value.
 
  • Like
Reactions: UncleNanard

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
UncleNanard
did you try this?
There's also possibly that: define config.missing_background = "black"


When it come to the default configuration, it's relatively difficult. It depend the version of Ren'Py used when creating the project from the SDK, what can be different to the version one now use. And on the other side of the problem, I have too many test projects to remember which version created them, while some have perhaps had a change in the configuration.
 
  • Like
Reactions: UncleNanard

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
did you try this?
Yes, but i removed it, i don't know why. Probably something don't work this night and i tried without ? I don't know but thanks.

UncleNanard


There's also possibly that: define config.missing_background = "black"


When it come to the default configuration, it's relatively difficult. It depend the version of Ren'Py used when creating the project from the SDK, what can be different to the version one now use. And on the other side of the problem, I have too many test projects to remember which version created them, while some have perhaps had a change in the configuration.
Now it work ! And this is very good, exactly what i wanted thank you very much. I m so happy !

But now, when i m ingame, the first right click goes to the menu, but when i quit this menu i have an error :


Code:
[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1898, in script
    "blabla blibli"
TypeError: 'NoneType' object has no attribute '__getitem__'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 1898, in script
    "blabla blibli"
  File "renpy/ast.py", line 721, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "renpy/exports.py", line 1419, in say
    who(what, *args, **kwargs)
  File "renpy/character.py", line 1249, in __call__
    self.do_display(who, what, cb_args=self.cb_args, dtt=dtt, **display_args)
  File "renpy/character.py", line 901, in do_display
    **display_args)
  File "renpy/character.py", line 647, in display_say
    rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3325, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3676, in interact_core
    new_widget=layers_root)
  File "renpy/curry.py", line 48, in __call__
    return self.callable(*(self.args + args), **merged_kwargs)
  File "renpy/display/movetransition.py", line 339, in OldMoveTransition
    rv = merge_slide(old_widget, new_widget)
  File "renpy/display/movetransition.py", line 218, in merge_slide
    f = merge_slide(old.layers[layer], new.layers[layer])
  File "renpy/display/movetransition.py", line 277, in merge_slide
    old_sl = old.scene_list[:]
TypeError: 'NoneType' object has no attribute '__getitem__'

Windows-10-10.0.22000
Ren'Py 7.4.11.2266
project game 1.0
Sat Feb  5 15:49:10 2022
[/CODE]

This error happen on all scene in the game except on the choice screen. (i can make a gif if you want, because i know my explanation are shit in english :( )
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
But now, when i m ingame, the first right click goes to the menu, but when i quit this menu i have an error :

Code:
 File "renpy/display/movetransition.py", line 277, in merge_slide
    old_sl = old.scene_list[:]
TypeError: 'NoneType' object has no attribute '__getitem__'
This error happen on all scene in the game except on the choice screen.
Hmm...
[globally speaking]
The error happen when Ren'Py try to get a copy of all the scenes actually displayed on the screen. And it happen because the list of those scene... is not a list :/

And I absolutely don't see what can be the cause of this. That it's involuntarily an empty list, I could understand, but that it's not even a list anymore... The only cause I possibly see for this wouldn't throw this error, because it wouldn't happen when the game is played.

So far, my guess is that you have added the blur+darker effect to a screen that shouldn't have it ; without really understand why it would throw this error.

Therefore, go back to the screens, and for all of them, comment the on "show" and on "hide" lines, by putting a # as first character for the line.
Then test is you still have the error. This will tell if it's related to this, or to something else.
Then, if the error disappeared, uncomment the two lines for one screen (starting by the first on in the file, in order to make this easier), and test.
Continue like this, uncommenting one screen after the other, until the error come back.
This will tell you which is the culprit, what can possibly help.
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,514
1,530
For now i just add it in here :

Capture d’écran 2022-02-05 174702.png

This is the first lane who give the error.

i tried to put it in another place, like game_menu but the error is in all place.

Maybe it"s because when i add this : define config.missing_background = "black" i have a crash with a traceback, so i didn't add it :


Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 1817, in script
    define config.missing_background = "black"
  File "game/screens.rpy", line 1817, in script
    define config.missing_background = "black"
  File "renpy/common/000namespaces.rpy", line 11, in set
    setattr(self.nso, name, value)
Exception: config.missing_background is not a known configuration variable.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/bootstrap.py", line 331, in bootstrap
    renpy.main.main()
  File "renpy/main.py", line 560, in main
    renpy.game.context().run(node)
  File "game/screens.rpy", line 1817, in script
    define config.missing_background = "black"
  File "game/screens.rpy", line 1817, in script
    define config.missing_background = "black"
  File "renpy/ast.py", line 2213, in execute
    self.set()
  File "renpy/ast.py", line 2228, in set
    ns.set(self.varname, value)
  File "renpy/common/000namespaces.rpy", line 11, in set
    setattr(self.nso, name, value)
  File "renpy/defaultstore.py", line 106, in __setattr__
    raise Exception('config.%s is not a known configuration variable.' % (name))
Exception: config.missing_background is not a known configuration variable.

Windows-10-10.0.22000
Ren'Py 7.4.11.2266

Sat Feb  5 17:57:13 2022
i will try to comment and uncommenting all the screens.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Code:
[...]
  File "renpy/common/000namespaces.rpy", line 11, in set
    setattr(self.nso, name, value)
Exception: config.missing_background is not a known configuration variable.
[...]
Ren'Py 7.4.11.2266
What the fuck is this error ?
You don't have permission to view the spoiler content. Log in or register now.
And it's not you, I tried with the 7.4.11 and effectively it throw this error, while like you can see the variable is used... Worse, if you launch the game from the SDK (so with the developer mode enabled) and type config.missing_background in the console, well you'll see that it's value is already "black"...

So, Ren'Py complain, saying that a configuration variable is not known, while using it and being able to show its value. But well, I understand why the error happen...
I guess that it's yet another regression due to the journey to the 8.x :(


All this being said:

I don't know what is the new configuration value (probably not documented) that lead to the use of the checkered background. But what I know is that I built the distribution using the 7.4.11 SDK, and the said checkered background disappeared. I assume that it's present only when the developer mode is enabled, to help visualize some errors.
But verify before you'll publish the first release, just to be sure.


BUT all this don't explain the error you are getting.

To the exception of the "missing_background" issue, the code works fine with the version 7.4.11. I can back in time, using my initial code that target only the menu, added the "on based" version, messed with both, removing this or that, trying to reproduce an error you could have made by forgetting something, but I never had this error.

I assume that there's something else, but I really don't see what it can be.