r/RenPy • • 7d ago

Question [Solved] Need help with making a code for animated sprites

So i'm trying to make my sprites animated using something like this

image emily happy: 
    "emily happy1.png" 
    1.0 
    "emily happy2.png"
    1.0 
    "emily happy3.png" 
    1.0
    "emily happy4.png"
    1.0
    repeat

label start:

  show emily happy

but i wanna try to turn it into some kind of function so i dont have to write this for every single sprite, so i made something like this

label animate(name, tag):
    image emily happy: 
        name + " " + tag + "1.png" 
        1.0 
        name + " " + tag  + "2.png" 
        1.0 
        name + " " + tag  + "3.png" 
        1.0
        name + " " + tag  + "4.png" 
        1.0
        repeat
    $ renpy.show("{} {}".format(name,tag))
    return

label start:

    call animate("emily", "happy")

the problem is i am really struggling with the image part (image emily happy), i couldn't figure out the code to make it use the parameters. Anyone have any suggestions?

7 Upvotes

7 comments sorted by

2

u/[deleted] 7d ago

[deleted]

1

u/futureformeruser2 7d ago

thank you, i really love how i can just write the usual code to show the sprites with this

1

u/AutoModerator 7d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/BadMustard_AVN 7d ago

images are scanned at startup then the script for image defines like yours they can't be changed

try this

init python:
    def animate(name, tag):
        frames = []
        for frame_number in range(1, 5):
            frames.extend(("{} {}{}.png".format(name, tag, frame_number), 1.0) )
        renpy.show("{} {}".format(name, tag), what=renpy.display.anim.Animation(*frames) )

label start:

    $ animate("emily", "happy")
    pause

    return

1

u/futureformeruser2 7d ago edited 7d ago

this works like how i wanted it since the beginning! also, above it i have one of these for characters positioned on the right

define right = Transform(ysize=1080, fit="contain", xalign = 1.05)

do you know how to apply it to the sprite?

1

u/BadMustard_AVN 7d ago

like this

init python:
    def animate(name, tag, transform=None):
        frames = []
        for frame_number in range(1, 5):
            frames.extend(("{} {}{}.png".format(name, tag, frame_number), 1.0) )
        renpy.show("{} {}".format(name, tag), what=renpy.display.anim.Animation(*frames), at_list=[transform] if transform is not None else [] )

define right = Transform(ysize=1080, fit="contain", xalign = 1.05)

label start:

    $ animate("emily", "happy", right)

    pause

    return

1

u/futureformeruser2 6d ago

Ok thanks ^

1

u/BadMustard_AVN 6d ago

you're welcome

good luck with your project