Revision: 3575
Updated Code
at August 15, 2007 09:18 by n3x
Updated Code
def __init__(self, frames, time): """frames stores tuples (duration in ms, image-surf)""" self.start_time = time # personally, i would define the frames tuples the other way around and # just turn this around: durations, self.frame_list = zip(*frames) # next line does the same as # reduce(lambda l, v: l + [v + l[-1]], durations[1:], [durations[0]]) ;-> self.frame_end_time = [sum(durations[:i + 1]) for i in xrange(len(durations))] self.run_time = self.frame_end_time[-1] self.image = self.frame_list[0][1] self.rect = self.image.get_rect() def update(self, time): play_position = (time - self.start_time) % self.run_time # the above doesn't really work with a pausing feature, but you could # remember the pause time, and when you unpause, recompute the start_time for i, f in enumerate(self.frame_end_time): if play_position <= f: break self.image = self.frame_list[i] self.rect = self.image.get_rect()
Revision: 3574
Updated Code
at August 15, 2007 08:44 by n3x
Updated Code
def __init__(self, frames, time): """frames stores tuples (duration in ms, image-surf)""" self.start_time = time # personally, i would define the frames tuples the other way around and # just turn this around: durations, self.frame_list = zip(*frames) # next line does the same as # reduce(lambda l, v: l + [v + l[-1]], durations[1:], [durations[0]]) ;-> self.frame_end_time = [sum(durations[:i + 1]) for i in xrange(len(durations))] self.run_time = self.frame_end_time[-1] self.image = self.frame_list[0][1] self.rect = self.image.get_rect() def update(self, time): play_position = (time - self.start_time) % self.run_time # the above doesn't really work with a pausing feature, but you could # remember the pause time, and when you unpause, recompute the start_time for i, f in enumerate(self.frame_end_time): if play_position > f: continue break self.image = self.frame_list[i] self.rect = self.image.get_rect()
Revision: 3573
Updated Code
at August 15, 2007 08:03 by n3x
Updated Code
def __init__(self, frames, time): """frames stores tuples (duration in ms, image-surf)""" self.start_time = time # personally, i would define the frames tuples the other way around and # just turn this around: durations, self.frame_list = zip(*frames) # next line does the same as # reduce(lambda l, v: l + [v + l[-1]], durations[1:], [durations[0]]) ;-> self.frame_end_time = [sum(durations[:i + 1]) for i in xrange(len(durations))] self.run_time = self.frame_end_time[-1] self.image = self.frame_list[0][1] self.rect = self.image.get_rect() def update(self, time): play_position = (time - self.start_time) % self.run_time # the above doesn't really work with a pausing feature, but you could # remember the pause time, and when you unpause, recompute the start_time for i, f in reversed(list(enumerate(self.frame_end_time))): if play_position < f: break self.image = self.frame_list[i] self.rect = self.image.get_rect()
Revision: 3572
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 15, 2007 03:52 by n3x
Initial Code
def __init__(self, time): self.frame_list = ... # stores tuples (duration in ms, image-surf) self.start_time = time self.image = self.frame_list[0][1] self.rect = self.image.get_rect() def update(self, time): play_position = time - self.start_time # the above doesn't really work with a pausing feature, but you could # remember the pause time, and when you unpause, recompute the start_time next_frame_start = 0 for i in xrange(len(self.frame_list)): duration, img = self.frame_list[i] next_frame_start += duration if next_frame_start > play_position: break self.image = img self.rect = img.get_rect()
Initial URL
Initial Description
Initial Title
class TimedFrameAnimation(Sprite)
Initial Tags
Initial Language
Python