forked from zcr1/OSGCC6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_strip_anim.py
executable file
·47 lines (42 loc) · 1.54 KB
/
sprite_strip_anim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import spritesheet
class SpriteStripAnim(object):
"""sprite strip animator
This class provides an iterator (iter() and next() methods), and a
__add__() method for joining strips which comes in handy when a
strip wraps to the next row.
"""
def __init__(self, filename, rect, count, colorkey=None, loop=False, frames=1):
"""construct a SpriteStripAnim
filename, rect, count, and colorkey are the same arguments used
by spritesheet.load_strip.
loop is a boolean that, when True, causes the next() method to
loop. If False, the terminal case raises StopIteration.
frames is the number of ticks to return the same image before
the iterator advances to the next image.
"""
self.filename = filename
ss = spritesheet.spritesheet(filename)
self.images = ss.load_strip(rect, count, colorkey)
self.i = 0
self.loop = loop
self.frames = frames
self.f = frames
def iter(self):
self.i = 0
self.f = self.frames
return self
def next(self):
if self.i >= len(self.images):
if not self.loop:
raise StopIteration
else:
self.i = 0
image = self.images[self.i]
self.f -= 1
if self.f == 0:
self.i += 1
self.f = self.frames
return image
def __add__(self, ss):
self.images.extend(ss.images)
return self