[solved] define animation inside python function

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved] define animation inside python function

#1 Post by Kia »

I'm trying to define some animation using python, a single frame was easy:

Code: Select all

    def create_animations(name = "laria"):
        img = "rpg/npc/{}/sheet.png".format(name)
        d = Crop((32, 0, 32, 32), img)
        renpy.image(name, d)
however, I can't find any reference on how to construct an animation object in python, for example I need to create a displayable from:

Code: Select all

image You down walk:
    Crop((0, 0, 32, 32), img)
    pause .1
    Crop((32, 0, 32, 32), img)
    pause .1
    Crop((64, 0, 32, 32), img)
    pause .1
    Crop((32, 0, 32, 32), img)
    pause .1
    repeat
to pass to renpy.image(name, d)
I assume it must be something like Image(img1, 0.1, img2, 0.1, img3, 0.1, img4, 0.1, repeat=True) but I can't find the correct format. anybody knows the proper way to do it?
Last edited by Kia on Sat Sep 11, 2021 2:24 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: define animation inside python function

#2 Post by Alex »

Kia wrote: Sun Sep 05, 2021 5:29 am I'm trying to define some animation using python...
Try DynamicDisplayable - https://www.renpy.org/doc/html/displaya ... isplayable

There was some posts about it
viewtopic.php?f=8&t=61883&p=541642&hili ... le#p541642
viewtopic.php?f=8&t=55390&p=512313&hili ... le#p512313

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: define animation inside python function

#3 Post by Kia »

I can see how that can be used to display a different frame based on how long the image was on the screen, but before diving into that rabbit hole, is it really the only way to loop through few frames of animation?
doesn't image have a python equivalent that takes a tuple of every frame and their delays to loop through them?
keep in mind that I don't want to have an image that I can change, I just want to define the same animated image but inside python so I can automate the defining process.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: define animation inside python function

#4 Post by hell_oh_world »

Adding to what Alex answered, I did something similar before...
viewtopic.php?p=540520#p540520
You can replace the frames with any displayable you want.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: define animation inside python function

#5 Post by Kia »

I've finally got time to try it and it works, thank you both.
Now I'm wondering: since we're calling this function constantly for every animated object of the same type. Does it come with a bigger performance hit than animations that are defined the regular way? Or regular animation does the same thing in the background as well?

Post Reply

Who is online

Users browsing this forum: Google [Bot]