This is the code I have created:
Code: Select all
class AnimatedCounter:
def __init__(self, hit, delay):
self.hit = hit ## The value to be reached
self.delay = delay ## The time it takes to get from 0 to self.hit
self.update_rate = None ## Used to calculate the update interval
self.update_count = 0 ## The current count
def count(self, st, at):
if self.update_rate is None:
self.update_rate = self.delay / self.hit
if self.update_count < self.hit:
self.update_count += 1
return Text("%s" % self.update_count), self.update_rate
Code: Select all
screen anim_num(delay, hit):
default counter = AnimatedCounter(hit = hit, delay = delay)
add DynamicDisplayable(counter.count) align(0.5, 0.5)
This should work fine, but the time it takes to get from 0 to self.hit isn't appropriate, and I'm very aware that it's a bug in the arithmetic I'm using to calculate the update interval.
The calculation runs on:
Code: Select all
if self.update_rate is None:
self.update_rate = self.delay / self.hit
I appreciate the help guys!