Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
AnimationNode Class Reference

#include <CUAnimationNode.h>

Inheritance diagram for AnimationNode:
PolygonNode TexturedNode

Public Member Functions

int getSize ()
 
unsigned int getFrame ()
 
void setFrame (int frame)
 
 ~AnimationNode ()
 
bool initWithFilmstrip (Texture2D *texture, int rows, int cols, int size)
 
- Public Member Functions inherited from PolygonNode
virtual std::string getDescription () const override
 
virtual void draw (Renderer *renderer, const Mat4 &transform, uint32_t flags) override
 
virtual ~PolygonNode (void)
 
- Public Member Functions inherited from TexturedNode
virtual void setTexture (const std::string &filename)
 
virtual void setTexture (Texture2D *texture) override
 
virtual Texture2D * getTexture () const override
 
virtual void setPolygon (float *vertices, int size, int offset=0)
 
virtual void setPolygon (const Poly2 &poly)
 
virtual void setPolygon (const Rect &rect)
 
const Poly2getPolygon () const
 
virtual void shiftPolygon (float dx, float dy)
 
const Rect & getBoundingRect () const
 
void setBlendFunc (const BlendFunc &blendFunc) override
 
const BlendFunc & getBlendFunc () const override
 
virtual void setOpacityModifyRGB (bool modify) override
 
virtual bool isOpacityModifyRGB (void) const override
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual ~TexturedNode (void)
 
virtual bool init () override
 
virtual bool init (float *vertices, int size, int offset=0)
 
virtual bool init (const Poly2 &poly)
 
virtual bool init (const Rect &rect)
 
virtual bool initWithFile (const std::string &filename)
 
virtual bool initWithFile (const std::string &filename, float *vertices, int size, int offset=0)
 
virtual bool initWithFile (const std::string &filename, const Poly2 &poly)
 
virtual bool initWithFile (const std::string &filename, const Rect &rect)
 
virtual bool initWithTexture (Texture2D *texture)
 
virtual bool initWithTexture (Texture2D *texture, float *vertices, int size, int offset=0)
 
virtual bool initWithTexture (Texture2D *texture, const Poly2 &poly)
 
virtual bool initWithTexture (Texture2D *texture, const Rect &rect)
 

Static Public Member Functions

static AnimationNodecreate (Texture2D *texture, int rows, int cols)
 
static AnimationNodecreate (Texture2D *texture, int rows, int cols, int size)
 
- Static Public Member Functions inherited from PolygonNode
static PolygonNodecreate ()
 
static PolygonNodecreate (float *vertices, int size, int offset=0)
 
static PolygonNodecreate (const Poly2 &poly)
 
static PolygonNodecreate (const Rect &rect)
 
static PolygonNodecreateWithFile (const std::string &filename)
 
static PolygonNodecreateWithFile (const std::string &filename, float *vertices, int size, int offset=0)
 
static PolygonNodecreateWithFile (const std::string &filename, const Poly2 &poly)
 
static PolygonNodecreateWithFile (const std::string &filename, const Rect &rect)
 
static PolygonNodecreateWithTexture (Texture2D *texture)
 
static PolygonNodecreateWithTexture (Texture2D *texture, float *vertices, int size, int offset=0)
 
static PolygonNodecreateWithTexture (Texture2D *texture, const Poly2 &poly)
 
static PolygonNodecreateWithTexture (Texture2D *texture, const Rect &rect)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: AnimationNode()
 
- Public Attributes inherited from PolygonNode
CC_CONSTRUCTOR_ACCESS __pad0__: PolygonNode(void)
 
- Public Attributes inherited from TexturedNode
CC_CONSTRUCTOR_ACCESS __pad0__: TexturedNode(void)
 

Additional Inherited Members

- Protected Member Functions inherited from PolygonNode
virtual void generateRenderData () override
 
- Protected Member Functions inherited from TexturedNode
TrianglesCommand::Triangles & allocTriangles (const Poly2 &poly)
 
void clearRenderData ()
 
void updateColor () override
 
void updateBlendFunc ()
 
void updateTextureCoords ()
 
- Protected Attributes inherited from TexturedNode
Texture2D * _texture
 
Poly2 _polygon
 
BlendFunc _blendFunc
 
bool _insideBounds
 
bool _opacityModifyRGB
 
TrianglesCommand _command
 
TrianglesCommand::Triangles _triangles
 
bool _flipHorizontal
 
bool _flipVertical
 

Detailed Description

Class to support simple film strip animation

A filmstrip is just a sprite sheet. The creation API is very similar to the class Sprite. However, you must also specify the rows and columns in the sprite sheet so that it can break up the images for you.

The constructors always set this object equal to a rectangle the same size as a single frame in the sprite sheet. However, this class extends PolygonNode and not Sprite. Therefore you could conceivably animate the filmstrip over polygons. This can have undesirable effects if the polygon coordinate extend beyond a single animation frame; the Cocos2d renderer does not allow us to wrap a single frame of a texture atlas.

For example, suppose you have a filmstrip where each frame has a given width and height. Then setting the polygon to a triangle with vertices (0,0), (width/2, height), and (width,height) is okay. However, the vertices (0,0), (width, 2*height), and (2*width, height) is not.

Constructor & Destructor Documentation

AnimationNode::~AnimationNode ( )
inline

Disposes of a filmstrip and its contents

Member Function Documentation

NS_CC_BEGIN AnimationNode * AnimationNode::create ( Texture2D *  texture,
int  rows,
int  cols 
)
static

Creates a new filmstrip node from the given texture.

The size of the node is equal to the size of a single frame in the filmstrip. To resize the node, scale it up or down. Do NOT change the polygon, as that will interfere with the animation.

Parameters
textureThe texture image to use
rowsThe number of rows in the filmstrip
colsThe number of columns in the filmstrip

a reference to this texture

Returns
The allocated filmstrip as an autorelease object
AnimationNode * AnimationNode::create ( Texture2D *  texture,
int  rows,
int  cols,
int  size 
)
static

Creates a new filmstrip from the given texture.

The parameter size is to indicate that there are unused frames in the filmstrip. The value size must be less than or equal to rows*cols, or this constructor will raise an error.

The size of the node is equal to the size of a single frame in the filmstrip. To resize the node, scale it up or down. Do NOT change the polygon, as that will interfere with the animation.

Parameters
textureThe texture image to use
rowsThe number of rows in the filmstrip
colsThe number of columns in the filmstrip
sizeThe number of frames in the filmstrip

a reference to this texture

Returns
The allocated filmstrip as an autorelease object
unsigned int AnimationNode::getFrame ( )
inline

Returns the current active frame.

Returns
the current active frame.
int AnimationNode::getSize ( )
inline

Returns the number of frames in this filmstrip.

Returns
the number of frames in this filmstrip.
bool AnimationNode::initWithFilmstrip ( Texture2D *  texture,
int  rows,
int  cols,
int  size 
)

Initializes the film strip with the given texture.

The parameter size is to indicate that there are unused frames in the filmstrip. The value size must be less than or equal to rows*cols, or this constructor will raise an error.

The size of the node is equal to the size of a single frame in the filmstrip. To resize the node, scale it up or down. Do NOT change the polygon, as that will interfere with the animation.

Parameters
textureThe texture image to use
rowsThe number of rows in the filmstrip
colsThe number of columns in the filmstrip
sizeThe number of frames in the filmstrip

a reference to this texture

Returns
True if initialization was successful; false otherwise.
void AnimationNode::setFrame ( int  frame)

Sets the active frame as the given index.

If the frame index is invalid, an error is raised.

Parameters
framethe index to make the active frame

The documentation for this class was generated from the following files: