Ren'Py How do you create animations in renpy?

BigCrow

Newbie
Game Developer
Apr 29, 2018
18
25
How do you create animations in renpy? Does anyone have experience, or tried something similar?
 

Papa Ernie

Squirrel!?
Uploader
Donor
Dec 4, 2016
12,333
48,130

About 27,800 results (0.47 seconds) ::|:
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
It depends on exactly what type of animation you're trying to create.

If you have a static image and you want to move it across the screen (example, have a character slide in from the left or right) you would use the Ren'py transform language, which allows you to move images around with easing functions and the like.

If you're trying to create the illusion of a movie by using a series of still frames, you can take advantage of the fact that every "image" in Ren'py is actually a "displayable," and can be built up using sequences of other displayables with delays between them. So, for example, you can do:
Code:
image myAnimation:
    "frame1.png"
    0.1
    "frame2.png"
    0.1
    "frame3.png"
    0.1
    repeat
or, of course, you can just create and play a movie in the scene. :)

There's a pretty good summary of the ATL (Animation and Transform Language) with a lot of examples here:
 

BigCrow

Newbie
Game Developer
Apr 29, 2018
18
25
It depends on exactly what type of animation you're trying to create.

If you have a static image and you want to move it across the screen (example, have a character slide in from the left or right) you would use the Ren'py transform language, which allows you to move images around with easing functions and the like.

If you're trying to create the illusion of a movie by using a series of still frames, you can take advantage of the fact that every "image" in Ren'py is actually a "displayable," and can be built up using sequences of other displayables with delays between them. So, for example, you can do:
Code:
image myAnimation:
    "frame1.png"
    0.1
    "frame2.png"
    0.1
    "frame3.png"
    0.1
    repeat
or, of course, you can just create and play a movie in the scene. :)

There's a pretty good summary of the ATL (Animation and Transform Language) with a lot of examples here:
Thanks, just what I needed!
 

jones

Newbie
Aug 22, 2016
22
54
ATL is easiest to understand and use in Ren'py but it's limiting in some situations.

Many people will now use movie files like webm to play animations


If you want to use sprite sheets use the Filmstrip function


If you want to do some advanced stuff with lots of delays etc. you would define a custom function with this:
 

Alvidas

Newbie
Jul 2, 2018
35
15
1)
I was trying a clicker from a lemasoft example code and I have
init:
image x1 = "test.png"
image x2 = "test2.png"

if points >=100:
add "x1"
else:
add "x2"

#....
I tried various code to get an animated image composed of 2 images, instead of a single static one but could not figure it out.
Any ideas?

2)In options define config.mouse
When using an animated mouse cursor, I added a second image and is working OK except for the fact I can not insert a time for the animation (.5) to play at a certain rate I want.

*the indentation is getting messed up here, sorry.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
You can keep your indentation by putting your code between "code" and "/code" tags. (Use square brackets where I have the quotes - it's hard to show the actual tags themselves.)

Since you're using "add", I assume this is inside a screen?

Did you try:
Code:
image myAnimation:
    "frame1.png"
    0.1
    "frame2.png"
    0.1
    repeat

...

    add "myAnimation"
Note that you don't _have_ to put "image" declarations inside an "init" block - Ren'py handles that for you automatically.
 

Alvidas

Newbie
Jul 2, 2018
35
15
Thank you for the suggestions and information.

I started with the below code and worked from there for a simple clicker. Basically is calling a screen and the action is happening there. Unfortunately for some reason, the usual image animation method that you posted above does not work with this example inside the screen. Maybe I am doing something wrong, I don't know...
For a clicker, it would be nice to have animated images that cycle automatically, or while the player is clicking with the mouse (but having so much trouble with this simple image animation I didn't try what 'onClick:' option is for renpy) beside the 'if points >= number', then change image.




Code:
default points=10
default plus=2
default max_point=30
default clicked = True

init:
    image happy
    image neutral
    image sad
screen clicker:
    modal True
    timer .5 repeat True action [If(points <= 0, true=Jump("lost"), false=SetVariable("points", points - plus))]
    button:
        text "[points] / [max_point]" size 40
        background "#000"
        xpos .5
        ypos .5
        xysize(300, 300)
        action [SetVariable("clicked", True), If(points >= max_point, true=Jump("win"), false=SetVariable("points", points + plus)), Play("sound", "click.ogg")] #add click.ogg file to 'game' folder
    if points>=20:
        add "happy" xalign .3 yalign 1.0
    elif points<10:
        add "sad" xalign .3 yalign 1.0
    else:
        add "neutral " xalign .3 yalign 1.0
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
For Rich's example animation try
Code:
add ImageReference("myAnimation")
At least if the errors you were having were like myAnimation not defined.
 
  • Like
Reactions: Alvidas

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
So, it looks like what you're trying to do is have the player click a bunch of times, have the click accumulate points, have the points drain if they don't click. Now, how does the animation fit in? Is it just supposed to by cycling in the background as all this goes on? If so, you can create an animation via the mechanism I mentioned, and just add that image to the screen:
Code:
    add "myAnimation"
( @Epaddder - the "ImageReference" part isn't required. You do, however, have to have the name of the image in quotes inside the screen, since otherwise it gets interpreted as a variable. This is one of the differences between screen language and "regular" scripting.)

Or are you trying to set an image in the screen based on the number of points the person has accumulated so far? In that case, you can either do an "if chain" inside your screen - the way you've done at the end - or you can do the equivalent by creating an image using ConditionSwitch and "add" it to the screen:
Code:
image growsAsClicksAccumulate = ConditionSwitch(
    "points < 5", "small.png",
    "points < 10", "medium.png",
    "points < 15", "bigger.png",
    "points < 20", "almostThere.png",
    "True", "win.png")
"growsAsClicksAccumulate" is now a single image (which can be used anywhere) whose representation depends on the value of the "points" variable.
 

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
So you beat your head against the desk for a few hours, turn to Google for help, and find something that works... and I just needed quotes :coldsweat::oops:
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
So you beat your head against the desk for a few hours, turn to Google for help, and find something that works... and I just needed quotes :coldsweat::oops:
LOL. One of the things about Ren'py is that (a) there are approximately 683 different ways you can do something, (b) 7,921 different people have some up with solutions that are variations on those themes, (c) there are ~10 years worth of history and (d) the "best" way to do something has changed 27 times over those 10 years.

More seriously, when "screen language" was introduced to replace the way-way-old way of building screens using Python commands, PyTom realized that having local screen variables would be A Good Thing. And it is - there's just a ton of stuff you can do with them. (I've used them for screens that go through multiple states like zooming in on stuff, showing it, and then zooming back out, for example.) But that obviously conflicted with the way that the "normal" Ren'py scripting represented images, which is without quotes. If we were starting things over again from scratch, maybe the "normal" scripting wouldn't do that, but it's way too late for that now. :) So the solution was to treat un-quoted items as variable references to variables declared INSIDE the screen, and to quote anything else. When you "add" an image and Ren'py sees that you've passed it a string, it basically uses the content of that string and looks for it "outside" the screen instead of inside the screen. There are other things in screen language that work that way too - you quote something to refer to it so that Ren'py can see the name instead of the value. (Like SetVariable and SetScreenVariable)
 
  • Haha
Reactions: Penfold Mole

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
I think the thing that lead to the most confusion is that the example for add in the documentation is:
Code:
screen add_test():
    add "logo.png" xalign 1.0 yalign 0.0
Which read to me as use quotes as a stand in for relative paths... so if I was using a variable that I had declared somewhere else... why would I need to quote it :noexpression:

Thanks for the clarification though of why some things are in quotes and others are not... :)
 

Alvidas

Newbie
Jul 2, 2018
35
15
@Epaddder: I got exactly that error you mention previously, then I deleted the code, cause I was unable to fix it :)
@Rich: the brackets around ("image_name") did it. I had no idea the screen language interpreted it as a variable if not in brackets. Thank you so much. Now is working perfectly. I appreciate the info regarding condition switch, I will certainly look into, it seems another way to do what I am trying.

Why I wanted those animations? I have a sprite (character) and I would like it to 'blink', once in a while so the game is not so boring.
The player clicks and the score goes u, but if he is not clicking fast enough score goes down. If he reaches the necessary value sprite changes at certain numbers with 'if, elif, else, (similar with condition switch you wrote about, that seems more flexible as you can insert more images) and at maximum points jump to next level (label_win).
____________
I am looking for advice if changing image on click is possible and to have it inserted in the screen.
Example: 'sprite small' is on screen. On click I want to have a 'sprite medium' load and replace 'sprite small', then switch back to 'sprite small' when mouse button is up. Like a button, approximately. In my case I don't think 'show'/'hide' image is the way to go.
If you have any advice, I appreciate...
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
To the best of my knowledge, there isn't a good way to do "show one image while the mouse is down and another while the mouse is up" using just screen language. You could code that via a Creator Defined Displayable ( ), since that way you'd have access to the low-level PyGame events, but that's a whole 'nother kettle of fish.
 

Alvidas

Newbie
Jul 2, 2018
35
15
I have to study that information, before I hope to integrate it in the game. Thank you for the link!
 

Nymphs

Member
Mar 7, 2020
174
285
It depends on exactly what type of animation you're trying to create.

If you have a static image and you want to move it across the screen (example, have a character slide in from the left or right) you would use the Ren'py transform language, which allows you to move images around with easing functions and the like.

If you're trying to create the illusion of a movie by using a series of still frames, you can take advantage of the fact that every "image" in Ren'py is actually a "displayable," and can be built up using sequences of other displayables with delays between them. So, for example, you can do:
Code:
image myAnimation:
    "frame1.png"
    0.1
    "frame2.png"
    0.1
    "frame3.png"
    0.1
    repeat
or, of course, you can just create and play a movie in the scene. :)

There's a pretty good summary of the ATL (Animation and Transform Language) with a lot of examples here:
Hi. Thank you. I'm using this (looking at your guidance). But I have a problem: the minimize looping between 2 frames I can do is 0.015. Even if I set it lower than that, the animation in renpy will still run with 0.015 as the fastest.
Code:
image myAnimation:
    "frame1.png"
    0.015
    "frame2.png"
    0.015
    "frame3.png"
    0.015
    repeat
Do you know a way to set it lower than 0.015? Thanks a lot!
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,975
16,229
Do you know a way to set it lower than 0.015? Thanks a lot!
It's not possible. And honestly if you need to go below 0.1 second between two frames, then using Ren'py's ATL isn't the solution. You should make a real video instead. Not only it will be guaranty to be smoother, but it should also need less space.
 
  • Like
Reactions: Nymphs

Nymphs

Member
Mar 7, 2020
174
285
It's not possible. And honestly if you need to go below 0.1 second between two frames, then using Ren'py's ATL isn't the solution. You should make a real video instead. Not only it will be guaranty to be smoother, but it should also need less space.
Thank you.