CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::AnimateSprite Class Reference

#include <CUAnimateSprite.h>

Inheritance diagram for cugl::AnimateSprite:

Public Member Functions

 AnimateSprite ()
 
 ~AnimateSprite ()
 
void dispose ()
 
bool init ()
 
bool init (int start, int end, int repeat=1)
 
bool init (const std::vector< int > &frames)
 
bool init (const std::vector< int > &frames, const std::vector< float > &weights)
 
int getFrame (float t) const
 
const std::vector< int > & getSequence () const
 
const std::vector< float > & getWeights () const
 
void setSequence (const std::vector< int > &frames)
 
void setSequence (const std::vector< int > &frames, const std::vector< float > &weights)
 
int isUniform () const
 
void setUniform ()
 
template<typename T >
ActionFunction attach (const std::shared_ptr< T > &obj)
 

Static Public Member Functions

static std::shared_ptr< AnimateSpritealloc ()
 
static std::shared_ptr< AnimateSpritealloc (int start, int end, int repeat=1)
 
static std::shared_ptr< AnimateSpritealloc (const std::vector< int > &frames)
 
static std::shared_ptr< AnimateSpritealloc (const std::vector< int > &frames, const std::vector< float > &weights)
 

Protected Attributes

std::vector< int > _frameset
 
std::vector< float > _weights
 
bool _uniform
 

Detailed Description

This factory creates an action animating by spritesheet frames

Each frame in the sequence is given a set amount of time to display. The animation will not tween between frames, as it applies to a single scene graph node, and cannot interpolate images.

This class is actually a factory for creating movement actions. To create an action, call attach to an object with the method setFrame. The action will call that method over time to perform the animation. Note that this class contains no duration information. That is supplied when the action is added to ActionTimeline.

Constructor & Destructor Documentation

◆ AnimateSprite()

cugl::AnimateSprite::AnimateSprite ( )
inline

Creates an uninitialized animation.

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

◆ ~AnimateSprite()

cugl::AnimateSprite::~AnimateSprite ( )
inline

Deletes this animation instance, disposing all resources

Member Function Documentation

◆ alloc() [1/4]

static std::shared_ptr< AnimateSprite > cugl::AnimateSprite::alloc ( )
inlinestatic

Returns a newly allocated, degenerate animation action.

The animation sequence is empty, meaning no animation takes place.

Returns
a newly allocated, degenerate animation action.

◆ alloc() [2/4]

static std::shared_ptr< AnimateSprite > cugl::AnimateSprite::alloc ( const std::vector< int > &  frames)
inlinestatic

Returns a newly allocated animation sequence of uniform speed

The animation sequence is given by the specified vector. The animation will spend an equal amount of time on each frame.

Parameters
framesThe animation sequence
Returns
a newly allocated animation sequence of uniform speed

◆ alloc() [3/4]

static std::shared_ptr< AnimateSprite > cugl::AnimateSprite::alloc ( const std::vector< int > &  frames,
const std::vector< float > &  weights 
)
inlinestatic

Returns a newly allocated animation sequence of variable speed

The animation sequence is given by the first specified vector. The second vector specifies the weight of each frame. The weights specify the percentage of time spent on each frame. These weights must sum to

  1. If they do not, then only the initial segment of weights suming to 1 will be used; the other weights will be zeroed.

Both vectors must be the same length. They can be empty.

Parameters
framesThe animation sequence
weightsThe percentage of time to spend on each frame
Returns
a newly allocated animation sequence of variable speed

◆ alloc() [4/4]

static std::shared_ptr< AnimateSprite > cugl::AnimateSprite::alloc ( int  start,
int  end,
int  repeat = 1 
)
inlinestatic

Returns a newly allocated animation sequence of frames start to end (inclusive).

The animation sequence has start as its first frame and end as its last. Animation will be in frame order, with an equal amount of time spent on each frame. The value start must be less than (or equal to) end, as this action does not know the spritesheet size.

The repeat argument is optional. It specifies the number of times to repeat the animation sequence.

Parameters
startThe initial frame to animate
endThe final frame to animate
repeatThe number of times to repeat the sequence
Returns
a newly allocated animation sequence of frames start to end (inclusive).

◆ attach()

template<typename T >
ActionFunction cugl::AnimateSprite::attach ( const std::shared_ptr< T > &  obj)
inline

Returns an action attaching this animation to the given object

The object class must support the method setFrame, which it will call to perform the animation. This action will reference this object during the animation. Any changes to this object during that time may alter the animation.

Note that the action has no associated duration. That should be set when it is added to ActionTimeline.

Parameters
objThe object to attach
Returns
an action attaching this animation to the given scene node

◆ dispose()

void cugl::AnimateSprite::dispose ( )

Disposes all of the resources used by this animation.

A disposed action can be safely reinitialized.

◆ getFrame()

int cugl::AnimateSprite::getFrame ( float  t) const

Returns the frame to be animated at normalized time t in [0,1].

This method is used by the animation action to determine the current frame.

Returns
the frame to be animated at normalized time t in [0,1].

◆ getSequence()

const std::vector< int > & cugl::AnimateSprite::getSequence ( ) const
inline

Returns the sequence of frames used in this animation

Changing this value for an actively animating action can have undefined side effects.

Returns
the sequence of frames used in this animation

◆ getWeights()

const std::vector< float > & cugl::AnimateSprite::getWeights ( ) const
inline

Returns individual weights for each frame

The weights specify the percentage of time spent on each frame. These weights must sum to 1. If they do not, then only the initial segment of weights suming to 1 will be used; the other weights will be zeroed.

If this animation uses a uniform time step for each frame, this set will be empty.

Changing this value for an actively animating action can have undefined side effects.

Returns
the sequence of frames used in this animation

◆ init() [1/4]

bool cugl::AnimateSprite::init ( )
inline

Initializes a degenerate animation.

The animation sequence is empty, meaning no animation takes place.

Returns
true if initialization was successful.

◆ init() [2/4]

bool cugl::AnimateSprite::init ( const std::vector< int > &  frames)

Initializes an animation sequence of uniform speed

The animation sequence is given by the specified vector. The animation will spend an equal amount of time on each frame.

Parameters
framesThe animation sequence
Returns
true if initialization was successful.

◆ init() [3/4]

bool cugl::AnimateSprite::init ( const std::vector< int > &  frames,
const std::vector< float > &  weights 
)

Initializes an animation sequence of variable speed

The animation sequence is given by the first specified vector. The second vector specifies the weight of each frame. The weights specify the percentage of time spent on each frame. These weights must sum to

  1. If they do not, then only the initial segment of weights suming to 1 will be used; the other weights will be zeroed.

Both vectors must be the same length. They can be empty.

Parameters
framesThe animation sequence
weightsThe percentage of time to spend on each frame
Returns
true if initialization was successful.

◆ init() [4/4]

bool cugl::AnimateSprite::init ( int  start,
int  end,
int  repeat = 1 
)

Initializes an animation sequence of frames start to end (inclusive).

The animation sequence has start as its first frame and end as its last. Animation will be in frame order, with an equal amount of time spent on each frame. The value start must be less than (or equal to) end, as this action does not know the spritesheet size.

The repeat argument is optional. It specifies the number of times to repeat the animation sequence.

Parameters
startThe initial frame to animate
endThe final frame to animate
repeatThe number of times to repeat the sequence
Returns
true if initialization was successful.

◆ isUniform()

int cugl::AnimateSprite::isUniform ( ) const
inline

Returns true if this animation uses a uniform time step for all frames

Changing this value for an actively animating action can have undefined side effects.

Returns
true if this animation uses a uniform time step for all frames

◆ setSequence() [1/2]

void cugl::AnimateSprite::setSequence ( const std::vector< int > &  frames)

Sets the sequence of frames used in this animation

If this set has a different size than the one initial set, this setter will keep the overall animation duration, but will revert to a uniform time step.

Changing this value for an actively animating action can have undefined side effects.

Parameters
framesthe sequence of frames used in this animation

◆ setSequence() [2/2]

void cugl::AnimateSprite::setSequence ( const std::vector< int > &  frames,
const std::vector< float > &  weights 
)

Sets the sequence of frames used in this animation

The animation sequence is given by the first specified vector. The second vector specifies the weight of each frame. The weights specify the percentage of time spent on each frame. These weights must sum to

  1. If they do not, then only the initial segment of weights suming to 1 will be used; the other weights will be zeroed.

Both vectors must be the same length. They can be empty.

Changing this value for an actively animating action can have undefined side effects.

Parameters
framesThe animation sequence
weightsThe percentage of time to spend on each frame

◆ setUniform()

void cugl::AnimateSprite::setUniform ( )

Forces this animation to use a uniform time step for all frames

Changing this value for an actively animating action can have undefined side effects.

Member Data Documentation

◆ _frameset

std::vector<int> cugl::AnimateSprite::_frameset
protected

The list of frames to animate

◆ _uniform

bool cugl::AnimateSprite::_uniform
protected

Whether or not the timestep is uniform

◆ _weights

std::vector<float> cugl::AnimateSprite::_weights
protected

The percentage weight of each frame


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