First thing, when you come to this just stop. Don't think of your problem anymore and do something completely different (read a book, play a game, clean the house, whatever) for some time.
The more you struggle on your problem, the less you'll find the solution.
You must be registered to see the links
:
It can works without problem, but it's going too far for something this simple. One of the way to do it with DynamicDisplayable is to rely on a class ; something looking like this :
Python:
init python:
class Some_anim( renpy.Python.RevertableObject ):
def __init__( self, base, interval, nbFrames ):
self.__base = base
self.__interval = interval
self.__nbFrames = nbFrames
# /st/ is the number of seconds (float) since the first time
# this displayable started to be shown.
# /at/ is the number of seconds (float) since the first time
# a displayable with the same tag started to be shown.
def __call__( self, st, at ):
# The frame number is the displayed time modulo the
# interval. /int/ is probably useless here, but we works
# with float, so I'll be paranoid.
frame = int( st % self.__interval )
# Then we do a modulo to represent the loop.
frame %= self.__nbFrames
# Finally we return the right image, and ask to be called
# for the next interval.
return ( Image( self.__base.format( frame ) ), self.__interval )
image gaknee = DynamicDisplayable(Some_anim( "anim/g_stand{}.png", 0.10, 60 ) )
Or, relying on the fact that Ren'py will call the class with the right interval :
Python:
init python:
class Some_anim( renpy.Python.RevertableObject ):
def __init__( self, base, interval, nbFrames ):
self.__base = base
self.__interval = interval
self.__nbFrames = nbFrames
self.__frame = 0
def __call__( self, st, at ):
# We are displayed since less that the interval, so
# it's a new animation, restart from the first frame.
if st < self.__interval:
self.__frame = 0
# Loop if we reached the last frame.
if self.__frame > self.__nbFrames :
self.__frame = 0
# You need to increase the frame number after the
# computation of the name, so keep the return
# value...
retVal = ( Image( self.__base.format( self.__frame ) ), self.__interval )
# increase the frame number...
self.__frame += 1
# then finally return what was computed.
return retVal
image gaknee = DynamicDisplayable(Some_anim( "anim/g_stand{}.png", 0.10, 60 ) )
It's possible to pass parameters with a DynamicDisplayable, but I never tried it, so I'm not sure if they are free or limited to properties, nor how they effectively are passed.
But here, the solution just need a change of point of view. Instead of a displayable, it's a screen that should be used :
Code:
screen some_anim( base, interval, nbFrames ):
default frame = 0
timer interval repeat True action If( frame >= nbFrames, SetScreenVariable( "frame", 0 ), SetScreenVariable( "frame", frame + 1 ) )
add base
label start:
show screen some_anim( "anim/g_stand[frame].png", 0.10, 60 )
"Beautiful, isn't it ?"
"Well, at least the animation I used as validation is beautiful."
return
It's way simpler this way and really 100% on pure Ren'py.