![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUAnimateSprite.h>
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< AnimateSprite > | alloc () |
static std::shared_ptr< AnimateSprite > | alloc (int start, int end, int repeat=1) |
static std::shared_ptr< AnimateSprite > | alloc (const std::vector< int > &frames) |
static std::shared_ptr< AnimateSprite > | alloc (const std::vector< int > &frames, const std::vector< float > &weights) |
Protected Attributes | |
std::vector< int > | _frameset |
std::vector< float > | _weights |
bool | _uniform |
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
.
|
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.
|
inline |
Deletes this animation instance, disposing all resources
|
inlinestatic |
Returns a newly allocated, degenerate animation action.
The animation sequence is empty, meaning no animation takes place.
|
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.
frames | The animation sequence |
|
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
Both vectors must be the same length. They can be empty.
frames | The animation sequence |
weights | The percentage of time to spend on each frame |
|
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.
start | The initial frame to animate |
end | The final frame to animate |
repeat | The number of times to repeat the sequence |
|
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
.
obj | The object to attach |
void cugl::AnimateSprite::dispose | ( | ) |
Disposes all of the resources used by this animation.
A disposed action can be safely reinitialized.
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.
|
inline |
Returns the sequence of frames used in this animation
Changing this value for an actively animating action can have undefined side effects.
|
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.
|
inline |
Initializes a degenerate animation.
The animation sequence is empty, meaning no animation takes place.
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.
frames | The animation sequence |
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
Both vectors must be the same length. They can be empty.
frames | The animation sequence |
weights | The percentage of time to spend on each frame |
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.
start | The initial frame to animate |
end | The final frame to animate |
repeat | The number of times to repeat the sequence |
|
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.
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.
frames | the sequence of frames used in this animation |
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
Both vectors must be the same length. They can be empty.
Changing this value for an actively animating action can have undefined side effects.
frames | The animation sequence |
weights | The percentage of time to spend on each frame |
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.
|
protected |
The list of frames to animate
|
protected |
Whether or not the timestep is uniform
|
protected |
The percentage weight of each frame