Ren'Py [SOLVED]Change background and add tranformation to it on a change of a variable

tutankhamon

New Member
Nov 4, 2022
5
0
I'm trying to add a shake effect to the current background of the current label from an outside screen. I'm stuck. Read the documents and I've been searching in forums to find a solution.

There is a sanity system at my game:

Code:
screen sanitybar:
    vbox xalign 0.99:
       
        if sanity >= 75:
            add "images/sane.png" xalign 1.0 at sanity_transformation()
        elif sanity >= 50:
            add "images/less_sane.png" xalign 1.0 at sanity_transformation()
        elif sanity >= 25:
            add "images/not sane.png" xalign 1.0 at sanity_transformation()
        else:
            add "images/mad sane.png" xalign 1.0 at sanity_transformation()
        text "Sanity: [sanity]/100"
        bar value AnimatedValue(sanity, 100, 0.5) xalign 0.0 yalign 0.1 xmaximum 200
And I want to change the animation and background of the screen if sanity drops below 25:

Code:
label chapter0_0:
    scene bg:
        zoom 0.7
Problem is, inside the screen I can't use predeclared variables like bg. And I can only "add" new images. This results in adding another background on top of existing which is not what I'd like to do. I want to replace the existing one or add a shake animation to it.

I have a shake transformation:

Code:
init:
    transform my_shake:
        linear 0.1 xoffset -2 yoffset 2
        linear 0.1 xoffset 3 yoffset -3
        linear 0.1 xoffset 2 yoffset -2
        linear 0.1 xoffset -3 yoffset 3
        linear 0.1 xoffset 0 yoffset 0
        repeat
I'd appreciate the help. Any discussions you guys can link me to it, I'd be happy to read.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,180
14,904
Problem is, inside the screen I can't use predeclared variables like bg.
Why can't you ?


But well, let's say that you can't (what I really doubt about):
Python:
screen sanitybar():   # The trailing "()" is important, it permit you to benefit from screen optimization.

    vbox xalign 0.99:
        if sanity >= 75:
            add "images/sane.png" xalign 1.0 at sanity_transformation()
        elif sanity >= 50:
            add "images/less_sane.png" xalign 1.0 at sanity_transformation()
        elif sanity >= 25:
            add "images/not sane.png" xalign 1.0 at sanity_transformation()
        else:
            # And it's done, you've your shake effect when the sanity drop below 25.
            add "images/mad sane.png" xalign 1.0 at my_shake
        text "Sanity: [sanity]/100"
        bar value AnimatedValue(sanity, 100, 0.5) xalign 0.0 yalign 0.1 xmaximum 200
 

tutankhamon

New Member
Nov 4, 2022
5
0
Thank you for your reply. You were right, I can put images as variables. I just need to put them inside quotes. But I wanted to change the whole screen not the mad sane.png but I've got it covered. I'm posting my solution in case someone else needs it.

I moved my background to a screen and checked if sanity is below 25:

Code:
screen bg:
    zorder -1
    if sanity > 25:
        add "bg"
    else:
        add "bg" at my_shake