python/pysfml-animatedsprite-class-supplies-next-method-to-adjus

JSON

rev 3  |  foxhop  |  1349713745000  |  JSON

rev 2
rev 3
59                 self.current = 059                 self.current = 0
6060
n61Some example sprite timeline images:n61Some example sprite timeline images
62=========================================
6263
tt64 
65 
rev 2  |  foxhop  |  1316029180000  |  JSON

rev 1
rev 2
nn1PySFML AnimatedSprite class supplies Next method to adjust frames
2===================================================================
3 
1.. code-block:: python4.. code-block:: python
25
55                 self.complete = True58                 self.complete = True
56                 self.current = 059                 self.current = 0
tt60 
61Some example sprite timeline images:
62 
rev 1  |  foxhop  |  1316029020000  |  JSON

empty
rev 1
tt1.. code-block:: python
2 
3 from PySFML import sf
4 
5 class AnimatedSprite( sf.Sprite ):
6     def __init__( self, image, columns=1, rows=1, sequence=None, columnwidth=No
 >ne, rowheight=None ):
7         super( AnimatedSprite, self ).__init__( image )
8 
9         totalwidth, totalheight = self.GetSize() 
10 
11         if columnwidth: self.columnwidth = columnwidth 
12         else: self.columnwidth = int( totalwidth / columns )
13 
14         if rowheight: self.rowheight = rowheight
15         else: self.rowheight = int( totalheight / rows )
16 
17         if sequence:
18             self.sequence = sequence
19         else:
20             self.sequence = [ number for number in range( 1, ( columns * rows )
 > + 1 ) ]
21 
22         # create a frames list of column and row tuples
23         self.frames = [ (x,y) for y in range( 1, rows + 1 ) for x in range( 1, 
 >columns + 1 ) ]
24 
25         self.current = self.tick = self.complete = 0
26 
27         # set the first frame 
28         self.Next( self.tick )
29 
30     def Next( self, tickrate = 12 ):
31         """
32         Pass an optional tickrate.
33         If tick is greater or equal to tickrate:
34         Move the Sub Rectangle or view to the Next position.
35         Set complete to True when sequence finishes.
36         """
37         self.tick += 1
38 
39         if self.tick >= tickrate:
40 
41             self.tick = 0
42             column, row = self.frames[ self.sequence[ self.current ] - 1  ]
43 
44             subrect = sf.IntRect( 
45                 self.columnwidth * ( column - 1 ), 
46                 self.rowheight * ( row - 1 ), 
47                 self.columnwidth * column,
48                 self.rowheight * row
49             ) 
50 
51             self.SetSubRect( subrect ) 
52 
53             self.current += 1
54             if self.current >= len( self.sequence ):
55                 self.complete = True
56                 self.current = 0