Cornell Cocos
Cornell Extensions to Cocos2d
CUAnimationNode.h
1 //
2 // CUAnimationNode.h
3 // Cornell Extensions to Cocos2D
4 //
5 // Animation in Cocos2d is extremely heavy-weight. You have to create a lot of
6 // classes just to cycle through one simple filmstrip. While there are many reasons
7 // for this engineering decision (many of which I disagree with), it makes it very
8 // difficult to get started with animation in Cocos2d.
9 //
10 // This class helps makes things simple again. It provides a straight-forward
11 // filmstrip API, similar to what you saw in the intro class. However, note that
12 // this class extends PolygonNode and not Sprite. Therefore, you could conceivably
13 // animate the filmstrip over polygons. However, this can have undesirable effects
14 // if the polygon coordinates extend beyond a single animation frame; the Cocos2d
15 // renderer does not allow us to wrap a single frame of a texture atlas.
16 //
17 // Author: Walker White
18 // Version: 12/10/15
19 //
20 #ifndef __CU_FILM_STRIP_H__
21 #define __CU_FILM_STRIP_H__
22 
23 #include "CUPolygonNode.h"
24 #include <2d/CCSprite.h>
25 
26 
27 NS_CC_BEGIN
28 
29 #pragma mark -
30 #pragma mark AnimationNode
31 
51 class CC_DLL AnimationNode : public PolygonNode {
52 
53 private:
55  int _cols;
57  int _size;
59  int _frame;
61  Rect _bounds;
62 
63 public:
78  static AnimationNode* create(Texture2D* texture, int rows, int cols);
79 
99  static AnimationNode* create(Texture2D* texture, int rows, int cols, int size);
100 
101 
102 #pragma mark Attribute Accessors
103 
108  int getSize() { return _size; }
109 
115  unsigned int getFrame() { return _frame; }
116 
124  void setFrame(int frame);
125 
126 
127 #pragma mark Internal Constructors
128 CC_CONSTRUCTOR_ACCESS:
129  // WE FOLLOW THE TEMPLATE FOR SPRITE HERE
135  AnimationNode();
136 
141 
161  bool initWithFilmstrip(Texture2D* texture, int rows, int cols, int size);
162 
163 };
164 
165 NS_CC_END
166 
167 #endif /* defined(__CU_FILM_STRIP_H__) */
~AnimationNode()
Definition: CUAnimationNode.h:140
Definition: CUPolygonNode.h:60
static PolygonNode * create()
Definition: CUPolygonNode.cpp:31
Definition: CUAnimationNode.h:51
unsigned int getFrame()
Definition: CUAnimationNode.h:115
int getSize()
Definition: CUAnimationNode.h:108