[Solved] Shortening ATL Code

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
ThanksTnx
Newbie
Posts: 3
Joined: Fri Mar 12, 2021 5:43 am
itch: rollback
Contact:

[Solved] Shortening ATL Code

#1 Post by ThanksTnx »

Code: Select all

image animated:
"stills/0.png"
pause 0.08
"stills/1.png"
pause 0.08
"stills/2.png"
pause 0.08
"stills/3.png"
pause 0.08
"stills/4.png"
pause 0.08
"stills/5.png"
repeat
Is there some way to reduce this code?

Maybe by using a loop or something?
I'm still new to Ren'Py and Phython.

I might have an animation that requires even more images so I would like some help or ideas.
Thank you! :D
Last edited by ThanksTnx on Fri Mar 12, 2021 8:04 am, edited 1 time in total.

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

Re: Shortening ATL Code

#2 Post by hell_oh_world »

Shortest answer: Make it a movie instead. and use the Movie() displayable.
Another possible way:

Code: Select all

init python:
  def animation(st, at, frames=[], interval=None):
    frame_count = len(frames)

    if interval is None:
      interval = 1 / float(frame_count)

    return frames[int((st // interval) % frame_count)], interval

  def Animation(frames, interval=0.08):
    return DynamicDisplayable(animation, frames=frames, interval=interval)

image animated = Animation(
  frames=["stills/{}.png".format(i) for i in range(6)] # generate images "stills/0.png" up to "stills/5.png"
)

ThanksTnx
Newbie
Posts: 3
Joined: Fri Mar 12, 2021 5:43 am
itch: rollback
Contact:

Re: Shortening ATL Code

#3 Post by ThanksTnx »

Thanks I'll try that.

For I couldn't use the Movie() for this because its a character and it covers the background.
Or can you use Movie() without covering the background?

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

Re: Shortening ATL Code

#4 Post by hell_oh_world »

Or can you use Movie() without covering the background?
Yes, just make sure your movie file supports transparency, if it's rendered opaque, you can use the Movie displayable's mask parameter and pass another movie file that contains the black and white areas of the original movie. Black would represent those transparent areas, while white represents the opaque areas afaik.

ThanksTnx
Newbie
Posts: 3
Joined: Fri Mar 12, 2021 5:43 am
itch: rollback
Contact:

Re: Shortening ATL Code

#5 Post by ThanksTnx »

Do you have an example on how to use the mask for Movie()?
My videos just have this black background.

Edit:
Thanks I got it!
I'll prolly stick with the images as making Masks seem to be a hassle

Post Reply