CUGL
Cornell University Game Library
CUAnimationNode.h
1 //
2 // CUAnimationNode.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides a straight-forward filmstrip API, similar to what we
6 // use in the intro class. Note that this class extends PolygonNode, as it
7 // simply treats the node texture as a sprite sheet. Therefore, it is possible
8 // to animate the filmstrip over polygons. However, this can have undesirable
9 // effects if the polygon coordinates extend beyond a single animation frame.
10 //
11 // This class uses our standard shared-pointer architecture.
12 //
13 // 1. The constructor does not perform any initialization; it just sets all
14 // attributes to their defaults.
15 //
16 // 2. All initialization takes place via init methods, which can fail if an
17 // object is initialized more than once.
18 //
19 // 3. All allocation takes place via static constructors which return a shared
20 // pointer.
21 //
22 // CUGL zlib License:
23 // This software is provided 'as-is', without any express or implied
24 // warranty. In no event will the authors be held liable for any damages
25 // arising from the use of this software.
26 //
27 // Permission is granted to anyone to use this software for any purpose,
28 // including commercial applications, and to alter it and redistribute it
29 // freely, subject to the following restrictions:
30 //
31 // 1. The origin of this software must not be misrepresented; you must not
32 // claim that you wrote the original software. If you use this software
33 // in a product, an acknowledgment in the product documentation would be
34 // appreciated but is not required.
35 //
36 // 2. Altered source versions must be plainly marked as such, and must not
37 // be misrepresented as being the original software.
38 //
39 // 3. This notice may not be removed or altered from any source distribution.
40 //
41 // Author: Walker White
42 // Version: 12/1/16
43 //
44 #ifndef __CU_ANIMATION_NODE_H__
45 #define __CU_ANIMATION_NODE_H__
46 
47 #include "CUPolygonNode.h"
48 #include "../math/CURect.h"
49 #include "../renderer/CUTexture.h"
50 
51 
52 namespace cugl {
53 
54 #pragma mark -
55 #pragma mark AnimationNode
56 
77 class AnimationNode : public PolygonNode {
78 protected:
80  int _cols;
82  int _size;
84  int _frame;
87 
88 #pragma mark -
89 #pragma mark Constructors
90 public:
99  AnimationNode();
100 
109 
126  bool initWithFilmstrip(const std::shared_ptr<Texture>& texture, int rows, int cols) {
127  return initWithFilmstrip(texture,rows,cols,rows*cols);
128  }
129 
148  bool initWithFilmstrip(const std::shared_ptr<Texture>& texture, int rows, int cols, int size);
149 
150 
151 #pragma mark -
152 #pragma mark Static Constructors
153 
169  static std::shared_ptr<AnimationNode> alloc(const std::shared_ptr<Texture>& texture,
170  int rows, int cols) {
171  std::shared_ptr<AnimationNode> node = std::make_shared<AnimationNode>();
172  return (node->initWithFilmstrip(texture,rows,cols) ? node : nullptr);
173 
174  }
175 
194  static std::shared_ptr<AnimationNode> alloc(const std::shared_ptr<Texture>& texture,
195  int rows, int cols, int size) {
196  std::shared_ptr<AnimationNode> node = std::make_shared<AnimationNode>();
197  return (node->initWithFilmstrip(texture,rows,cols,size) ? node : nullptr);
198  }
199 
200 
201 #pragma mark Attribute Accessors
202 
207  int getSize() const { return _size; }
208 
214  unsigned int getFrame() const { return _frame; }
215 
223  void setFrame(int frame);
224 
225 
226 };
227 
228 }
229 
230 #endif /* __CU_ANIMATION_NODE_H__ */
unsigned int getFrame() const
Definition: CUAnimationNode.h:214
int _frame
Definition: CUAnimationNode.h:84
int _cols
Definition: CUAnimationNode.h:80
bool initWithFilmstrip(const std::shared_ptr< Texture > &texture, int rows, int cols)
Definition: CUAnimationNode.h:126
Definition: CUPolygonNode.h:79
int getSize() const
Definition: CUAnimationNode.h:207
Rect _bounds
Definition: CUAnimationNode.h:86
Definition: CURect.h:45
static std::shared_ptr< AnimationNode > alloc(const std::shared_ptr< Texture > &texture, int rows, int cols)
Definition: CUAnimationNode.h:169
static std::shared_ptr< AnimationNode > alloc(const std::shared_ptr< Texture > &texture, int rows, int cols, int size)
Definition: CUAnimationNode.h:194
void setFrame(int frame)
Definition: CUAnimationNode.h:52
int _size
Definition: CUAnimationNode.h:82
Definition: CUAnimationNode.h:77
~AnimationNode()
Definition: CUAnimationNode.h:108