Renpy programmatic animations?

Tlaero

Well-Known Member
Game Developer
Nov 24, 2018
1,034
5,080
I'm porting some of my older HTML/JavaScript games to Ren'py, and I'm trying to figure out which gameplay elements I can bring forward and which I need to leave behind.

In Renpy, I typically do animations this way:

Python:
label dwe_finale58:
    scene background
    show dwe_sex65a at Center
    show dwe_finale58_anim at Center
    "Yes you can..."
    jump dwe_finale59

default dwe_finale58_delay = 0.15

image dwe_finale58_anim:
    "dwe_sex65a.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a1.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a2.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a5.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a8.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a7.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a6.jpg"
    pause dwe_finale58_delay
    "dwe_sex65a3.jpg"
    pause dwe_finale58_delay
    repeat
This plays the 8 frames over and over again until the player clicks or hits space, and then jumps to the next label.

What I'd like to do is know which frame the animation was on when the player clicked and possibly act on that. For instance, maybe I would not advance if they weren't on a particular frame or frames, or maybe I'd jump to a different label for some frames than others. Things like that.

Is there any way to do this in Ren'py?

Thanks!
Tlaero
 

felipons

Fluffy, The Destroyer of Worlds
Modder
Game Developer
Jan 15, 2018
251
1,047
What comes in mind for me is that you could make a variable and store the last played frame.
There probably is a better solution, but it doesn't come to my mind right now.

I had to create a method to chance the value of "last_played_frame", because inside an "image" you can't change the value of the variable.
This way you can also use the same method for all your animations. And check the value inside "last_played_frame"

Note: I haven't actually tested, but I believe this works.

Python:
define last_played_frame = ''

init python:
    def LastFrame(frame):
        last_played_frame = frame

label dwe_finale58:
    scene background
    show dwe_sex65a at Center
    show dwe_finale58_anim at Center
    "Yes you can..."
    jump dwe_finale59

default dwe_finale58_delay = 0.15

image dwe_finale58_anim:
    "dwe_sex65a.jpg"
    LastFrame('dwe_sex65a')
    pause dwe_finale58_delay
    "dwe_sex65a1.jpg"
    LastFrame('dwe_sex65a1')
    pause dwe_finale58_delay
    "dwe_sex65a2.jpg"
    LastFrame('dwe_sex65a2')
    pause dwe_finale58_delay
    "dwe_sex65a5.jpg"
    LastFrame('dwe_sex65a5')
    pause dwe_finale58_delay
    "dwe_sex65a8.jpg"
    LastFrame('dwe_sex65a8')
    pause dwe_finale58_delay
    "dwe_sex65a7.jpg"
    LastFrame('dwe_sex65a7')
    pause dwe_finale58_delay
    "dwe_sex65a6.jpg"
    LastFrame('dwe_sex65a6')
    pause dwe_finale58_delay
    "dwe_sex65a3.jpg"
    LastFrame('dwe_sex65a3')
    pause dwe_finale58_delay
    repeat
 
Last edited:

Tlaero

Well-Known Member
Game Developer
Nov 24, 2018
1,034
5,080
That's a great idea. I'll give it a try. Thanks, felipons!

It occurs to me that Renpy must be doing something similar internally, since it knows which frame to play. I wonder if I can find the variable, etc that it's using and act on that.

Tlaero