CUGL 2.0
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::AnimationNode Class Reference

#include <CUAnimationNode.h>

Inheritance diagram for cugl::scene2::AnimationNode:
cugl::scene2::PolygonNode cugl::scene2::TexturedNode cugl::scene2::SceneNode

Public Member Functions

 AnimationNode ()
 
 ~AnimationNode ()
 
bool initWithFilmstrip (const std::shared_ptr< Texture > &texture, int rows, int cols)
 
bool initWithFilmstrip (const std::shared_ptr< Texture > &texture, int rows, int cols, int size)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
int getSize () const
 
unsigned int getFrame () const
 
void setFrame (int frame)
 
- Public Member Functions inherited from cugl::scene2::PolygonNode
 PolygonNode ()
 
 ~PolygonNode ()
 
virtual void setPolygon (const std::vector< Vec2 > &vertices) override
 
virtual void setPolygon (const Poly2 &poly) override
 
virtual void setPolygon (const Rect rect) override
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint) override
 
- Public Member Functions inherited from cugl::scene2::TexturedNode
 TexturedNode ()
 
 ~TexturedNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool init (const std::vector< Vec2 > &vertices)
 
bool init (const Poly2 &poly)
 
bool init (const Rect rect)
 
bool initWithFile (const std::string &filename)
 
bool initWithFile (const std::string &filename, const std::vector< Vec2 > &vertices)
 
bool initWithFile (const std::string &filename, const Poly2 &poly)
 
bool initWithFile (const std::string &filename, const Rect rect)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const std::vector< Vec2 > &vertices)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const Rect rect)
 
void setTexture (const std::string &filename)
 
void setTexture (const std::shared_ptr< Texture > &texture)
 
std::shared_ptr< Texture > & getTexture ()
 
const std::shared_ptr< Texture > & getTexture () const
 
const Poly2getPolygon () const
 
virtual void shiftPolygon (float dx, float dy)
 
const Rect getBoundingRect () const
 
void setBlendFunc (GLenum srcFactor, GLenum dstFactor)
 
GLenum getSourceBlendFactor () const
 
GLenum getDestinationBlendFactor () const
 
void setBlendEquation (GLenum equation)
 
GLenum getBlendEquation () const
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual std::string toString (bool verbose=false) const override
 
bool isAbsolute () const
 
void setAbsolute (bool flag)
 
virtual void setAnchor (const Vec2 anchor) override
 
virtual void setContentSize (const Size size) override
 
virtual void setContentSize (float width, float height) override
 
void refresh ()
 
const std::shared_ptr< Gradient > & getGradient () const
 
void setGradient (const std::shared_ptr< Gradient > &gradient)
 
- Public Member Functions inherited from cugl::scene2::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual bool initWithPosition (const Vec2 pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size size)
 
bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect rect)
 
bool initWithBounds (float x, float y, float width, float height)
 
virtual SceneNodecopy (SceneNode *dst)
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
 operator std::string () const
 
const Vec2 getPosition () const
 
void setPosition (const Vec2 &position)
 
void setPosition (float x, float y)
 
float getPositionX (void) const
 
void setPositionX (float x)
 
float getPositionY (void) const
 
void setPositionY (float y)
 
Vec2 getWorldPosition () const
 
const Size getContentSize () const
 
float getContentWidth () const
 
void setContentWidth (float width)
 
float getContentHeight () const
 
void setContentHeight (float height)
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
void setAnchor (float x, float y)
 
const Vec2 getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
virtual void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor ()
 
void setRelativeColor (bool flag)
 
std::shared_ptr< ScissorgetScissor () const
 
void setScissor (const std::shared_ptr< Scissor > &scissor)
 
void setScissor ()
 
const Vec2 getScale () const
 
float getScaleX () const
 
float getScaleY () const
 
void setScale (float scale)
 
void setScale (const Vec2 vec)
 
void setScale (float sx, float sy)
 
float getAngle ()
 
void setAngle (float angle)
 
const Mat4getAlternateTransform ()
 
void setAlternateTransform (const Mat4 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Mat4getNodeToParentTransform () const
 
Mat4 getParentToNodeTransform () const
 
Mat4 getNodeToWorldTransform () const
 
Mat4 getWorldToNodeTransform () const
 
Vec2 screenToNodeCoords (const Vec2 screenPoint) const
 
Vec2 worldToNodeCoords (const Vec2 worldPoint) const
 
Vec2 nodeToScreenCoords (const Vec2 nodePoint) const
 
Vec2 nodeToWorldCoords (const Vec2 nodePoint) const
 
Vec2 parentToNodeCoords (const Vec2 parentPoint) const
 
Vec2 nodeToParentCoords (const Vec2 nodePoint) const
 
void setZOrder (int z)
 
int getZOrder () const
 
bool isZDirty () const
 
void sortZOrder ()
 
size_t getChildCount () const
 
std::shared_ptr< SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< T > getChild (unsigned int pos) const
 
std::shared_ptr< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< T > getChildByName (const std::string name) const
 
std::vector< std::shared_ptr< SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< SceneNode > > & getChildren () const
 
void addChild (std::shared_ptr< SceneNode > child)
 
virtual void addChild (const std::shared_ptr< SceneNode > &child, int zval)
 
void addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag)
 
void addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag, int zval)
 
void addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string &name)
 
void addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string &name, int zval)
 
void swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false)
 
SceneNodegetParent ()
 
const SceneNodegetParent () const
 
Scene2getScene ()
 
const Scene2getScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint)
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch)
 
const std::shared_ptr< Layout > & getLayout () const
 
void setLayout (const std::shared_ptr< Layout > &layout)
 
virtual void doLayout ()
 

Static Public Member Functions

static std::shared_ptr< AnimationNodealloc (const std::shared_ptr< Texture > &texture, int rows, int cols)
 
static std::shared_ptr< AnimationNodealloc (const std::shared_ptr< Texture > &texture, int rows, int cols, int size)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::scene2::PolygonNode
static std::shared_ptr< PolygonNodealloc ()
 
static std::shared_ptr< PolygonNodealloc (const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodealloc (const Poly2 &poly)
 
static std::shared_ptr< PolygonNodealloc (const Rect rect)
 
static std::shared_ptr< PolygonNodeallocWithFile (const std::string &filename)
 
static std::shared_ptr< PolygonNodeallocWithFile (const std::string &filename, const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodeallocWithFile (const std::string &filename, const Poly2 &poly)
 
static std::shared_ptr< PolygonNodeallocWithFile (const std::string &filename, const Rect rect)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::scene2::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec2 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Size size)
 
static std::shared_ptr< SceneNodeallocWithBounds (float width, float height)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 

Protected Attributes

int _cols
 
int _size
 
int _frame
 
Rect _bounds
 
- Protected Attributes inherited from cugl::scene2::TexturedNode
std::string _classname
 
std::shared_ptr< Texture_texture
 
Poly2 _polygon
 
bool _absolute
 
bool _stretch
 
bool _rendered
 
Mesh< SpriteVertex2_mesh
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _flipHorizontal
 
bool _flipVertical
 
std::shared_ptr< Gradient_gradient
 
std::shared_ptr< Gradient_spriteGrad
 
- Protected Attributes inherited from cugl::scene2::SceneNode
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
std::shared_ptr< Scissor_scissor
 
Vec2 _scale
 
float _angle
 
Mat4 _transform
 
bool _useTransform
 
Mat4 _combined
 
std::vector< std::shared_ptr< SceneNode > > _children
 
SceneNode_parent
 
Scene2_graph
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
int _zOrder
 
bool _zDirty
 
std::shared_ptr< JsonValue_json
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::scene2::TexturedNode
virtual void generateRenderData ()
 
void clearRenderData ()
 
void updateTextureCoords ()
 
 CU_DISALLOW_COPY_AND_ASSIGN (TexturedNode)
 
- Static Protected Attributes inherited from cugl::scene2::PolygonNode
static SimpleTriangulator _triangulator
 

Detailed Description

Class to support simple film strip animation

The API for this class is very similar to PolygonNode, except that it treats the texture as a sprite sheet. This means that you must specify the rows and columns in the sprite sheet so that it can break up the images for you.

The basic constructors always set this object equal to a rectangle the same size as a single frame in the sprite sheet. However, you could conceivably animate the filmstrip over polygons, simpy by changing the shape via setPolygon. This can have undesirable effects if the polygon coordinate extend beyond a single animation frame. The basic 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. 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) are not okay.

Constructor & Destructor Documentation

◆ AnimationNode()

cugl::scene2::AnimationNode::AnimationNode ( )

Constructs a ActionNode with no filmstrip

You must initialize this object before use.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~AnimationNode()

cugl::scene2::AnimationNode::~AnimationNode ( )
inline

Releases all resources allocated with this node.

This will release, but not necessarily delete the associated texture. However, the polygon and drawing commands will be deleted and no longer safe to use.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr<AnimationNode> cugl::scene2::AnimationNode::alloc ( const std::shared_ptr< Texture > &  texture,
int  rows,
int  cols 
)
inlinestatic

Returns a newly allocated filmstrip node from the given texture.

This constructor assumes that the filmstrip is rectangular, and that there are no unused frames.

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
Returns
a newly allocated filmstrip node from the given texture.

◆ alloc() [2/2]

static std::shared_ptr<AnimationNode> cugl::scene2::AnimationNode::alloc ( const std::shared_ptr< Texture > &  texture,
int  rows,
int  cols,
int  size 
)
inlinestatic

Returns a newly allocated filmstrip node 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
Returns
a newly allocated filmstrip node from the given texture.

◆ allocWithData()

static std::shared_ptr<SceneNode> cugl::scene2::AnimationNode::allocWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
inlinestatic

Returns a newly allocated node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

 "span":     The number of frames in the filmstrip
 "cols":     An int specifying the number of columns
 "frame":    The initial starting frame.

All attributes are optional. However, if nothing is specified, it assumes that this is a degenerate filmstrip with just one frame. If only span is specified, it assumes that it is just one row.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
a newly allocated node with the given JSON specificaton.

◆ getFrame()

unsigned int cugl::scene2::AnimationNode::getFrame ( ) const
inline

Returns the current active frame.

Returns
the current active frame.

◆ getSize()

int cugl::scene2::AnimationNode::getSize ( ) const
inline

Returns the number of frames in this filmstrip.

Returns
the number of frames in this filmstrip.

◆ initWithData()

virtual bool cugl::scene2::AnimationNode::initWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
overridevirtual

Initializes a node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

 "span":     The number of frames in the filmstrip
 "cols":     An int specifying the number of columns
 "frame":    The initial starting frame.

All attributes are optional. However, if nothing is specified, it assumes that this is a degenerate filmstrip with just one frame. If only span is specified, it assumes that it is just one row.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithFilmstrip() [1/2]

bool cugl::scene2::AnimationNode::initWithFilmstrip ( const std::shared_ptr< Texture > &  texture,
int  rows,
int  cols 
)
inline

Initializes the film strip with the given texture.

This initializer assumes that the filmstrip is rectangular, and that there are no unused frames.

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
Returns
true if the filmstrip is initialized properly, false otherwise.

◆ initWithFilmstrip() [2/2]

bool cugl::scene2::AnimationNode::initWithFilmstrip ( const std::shared_ptr< Texture > &  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
Returns
true if the filmstrip is initialized properly, false otherwise.

◆ setFrame()

void cugl::scene2::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

Member Data Documentation

◆ _bounds

Rect cugl::scene2::AnimationNode::_bounds
protected

The size of a single animation frame (different from active polygon)

◆ _cols

int cugl::scene2::AnimationNode::_cols
protected

The number of columns in this filmstrip

◆ _frame

int cugl::scene2::AnimationNode::_frame
protected

The active animation frame

◆ _size

int cugl::scene2::AnimationNode::_size
protected

The number of frames in this filmstrip


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