There's basically two ways of doing this in Ren'Py. The first would be to use renpy.pause with a small or zero delay. The following code fills up a bar, having frames that nominally last .01 seconds.
Code: Select all
init python:
import time
python:
# range - the max value of the bar.
# start - the starting value of the bar.
# end - the ending value of the bar.
# delay - the time it takes to show the bar.
start = time.time()
while True:
fraction = (time.time() - start) / delay
if fraction >= 1.0:
break
ui.bar(range, start + fraction * (end - start), ...)
renpy.pause(.01)
I don't really recommend it, though. since starting a new interaction is a lot of work. Instead, it's best to use DynamicDisplayable, along with a much longer renpy.pause.
Code: Select all
init python:
def increase_bar(range, start, end, delay, st, at):
fraction = st / delay
return Bar(range, start - fraction * (end - start), ...), .01
curried_increase_bar = renpy.curry(increase_bar)
python:
ui.add(DynamicDisplayable(curried_increase_bar(range, start, end, delay)))
renpy.pause(delay)
Basically, the function is called at the start of each interaction. It's expected to return a pair containing two things:
* A displayable to show to the screen.
* The time until the displayable should change. The function will be called again in this amount of time, to get a new displayable.
Fundamentally, Ren'Py keeps control of the main loop of the program. This lets it handle things like image preloading, sound/music, and so on.