Page 1 of 1

using renpy.random for timing in an animated image / animation random time

Posted: Mon Oct 02, 2017 8:10 am
by würstlbaron
hello!

i want to randomize the time between frames of an animated image, like this:

Code: Select all

image eileen blinking:
    "eileen open eyes.png"
    pause renpy.random.random()
    "eileen closed eyes.png"
    pause 0.2
    repeat
however, when i do this, it seems that the randomized pause time is only determined once, and that value is then always used when displaying the image. how can i achieve an effect where the time is randomized anew with each repetition of the animation?

Re: using renpy.random for timing in an animated image / animation random time

Posted: Mon Oct 02, 2017 8:54 am
by Divona
Perhaps something like this:

Code: Select all

default blink_timer = renpy.random.random()

init python:
    def blink(trans, st, at):
        global blink_timer

        if st >= blink_timer:
            blink_timer = renpy.random.random()
            return None
        else:
            return 0

image eileen blinking:
    "eileen open eyes.png"
    function blink
    "eileen closed eyes.png"
    pause 0.2
    repeat
See ATL Function Statement for more info.

Re: using renpy.random for timing in an animated image / animation random time

Posted: Mon Oct 02, 2017 9:20 am
by würstlbaron
Divona wrote: Mon Oct 02, 2017 8:54 am Perhaps something like this: [...]
perfect, works like a charm like that. thank you! :D