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

#include <CUAnimateAction.h>

Inheritance diagram for cugl::scene2::Animate:
cugl::scene2::Action

Public Member Functions

 Animate ()
 
 ~Animate ()
 
void dispose ()
 
bool init ()
 
bool init (int start, int end, float time, int repeat=1)
 
bool init (const std::vector< int > &frames, float time)
 
bool init (const std::vector< int > &frames, const std::vector< float > &time)
 
int getFrame (float t) const
 
const std::vector< int > & getSequence () const
 
const std::vector< float > & getTimeSteps () const
 
void setSequence (const std::vector< int > &frames)
 
void setSequence (const std::vector< int > &frames, const std::vector< float > &time)
 
int isUniform () const
 
void setUniform ()
 
virtual std::shared_ptr< Actionclone () override
 
virtual void load (const std::shared_ptr< SceneNode > &target, Uint64 *state) override
 
virtual void update (const std::shared_ptr< SceneNode > &target, Uint64 *state, float dt) override
 
virtual std::string toString (bool verbose=false) const override
 
- Public Member Functions inherited from cugl::scene2::Action
 Action ()
 
 ~Action ()
 
float getDuration () const
 
void setDuration (float time)
 
 operator std::string () const
 

Static Public Member Functions

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

Protected Attributes

std::vector< int > _frameset
 
std::vector< float > _timestep
 
bool _uniform
 
- Protected Attributes inherited from cugl::scene2::Action
float _duration
 

Detailed Description

This action represents a sequence of film-strip frames for animation

Each frame in the sequence is given a set amount of time to display. The animation will not tween between frames. To do so would require a refactoring of the scene graph nodes.

An action contains only the definition of the animation. This can include information about the transform to use or the duration of the animation. However, it does not contain any attribute of the target. Hence, an action can be reapplied to different targets.

By itself, an action does nothing. It only specifies an action that may take place. To use an action, it must be passed to the ActionManager. The manager will create an action instance and animate that instance. While an action may be reused many times, an action instance corresponds to a single animation.

Constructor & Destructor Documentation

◆ Animate()

cugl::scene2::Animate::Animate ( )
inline

Creates an uninitialized animation action.

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

◆ ~Animate()

cugl::scene2::Animate::~Animate ( )
inline

Deletes this action instance, disposing all resources

Member Function Documentation

◆ alloc() [1/4]

static std::shared_ptr<Animate> cugl::scene2::Animate::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<Animate> cugl::scene2::Animate::alloc ( const std::vector< int > &  frames,
const std::vector< float > &  time 
)
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 number of seconds to spend on each frame. the overall animation duration is the sum of this vector.

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

Parameters
framesThe animation sequence
timeThe duration of each frame in the sequences
Returns
a newly allocated animation sequence of variable speed

◆ alloc() [3/4]

static std::shared_ptr<Animate> cugl::scene2::Animate::alloc ( const std::vector< int > &  frames,
float  time 
)
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, so that the total time spent animating is the one specified.

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

◆ alloc() [4/4]

static std::shared_ptr<Animate> cugl::scene2::Animate::alloc ( int  start,
int  end,
float  time,
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 filmstrip length.\

The repeat argument is optional. It specifies the number of time to repeat the animation sequence. The total animation time will include all repeats.

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

◆ clone()

virtual std::shared_ptr<Action> cugl::scene2::Animate::clone ( )
overridevirtual

Returns a newly allocated copy of this Action.

Returns
a newly allocated copy of this Action.

Reimplemented from cugl::scene2::Action.

◆ dispose()

void cugl::scene2::Animate::dispose ( )

Disposes all of the resources used by this action.

A disposed action can be safely reinitialized.

◆ getFrame()

int cugl::scene2::Animate::getFrame ( float  t) const

Returns the frame in the filmstrip to be animated at time index t in [0,1]

Returns
the frame in the filmstrip to be animated at time index t in [0,1]

◆ getSequence()

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

Returns the sequence of frames used in this animation

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

Returns
the sequence of frames used in this animation

◆ getTimeSteps()

const std::vector<float>& cugl::scene2::Animate::getTimeSteps ( ) const
inline

Returns individual time steps for each frame

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 effects.

Returns
the sequence of frames used in this animation

◆ init() [1/4]

bool cugl::scene2::Animate::init ( )
inline

Initializes a degenerate animation action.

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

Returns
true if initialization was successful.

◆ init() [2/4]

bool cugl::scene2::Animate::init ( const std::vector< int > &  frames,
const std::vector< float > &  time 
)

Initializes an animation sequence of variable speed

The animation sequence is given by the first specified vector. The second vector specifies the number of seconds to spend on each frame. the overall animation duration is the sum of this vector.

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

Parameters
framesThe animation sequence
timeThe duration of each frame in the sequences
Returns
true if initialization was successful.

◆ init() [3/4]

bool cugl::scene2::Animate::init ( const std::vector< int > &  frames,
float  time 
)

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, so that the total time spent animating is the one specified.

Parameters
framesThe animation sequence
timeThe animation duration
Returns
true if initialization was successful.

◆ init() [4/4]

bool cugl::scene2::Animate::init ( int  start,
int  end,
float  time,
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 filmstrip length.

The repeat argument is optional. It specifies the number of time to repeat the animation sequence. The total animation time will include all repeats.

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

◆ isUniform()

int cugl::scene2::Animate::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 effects.

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

◆ load()

virtual void cugl::scene2::Animate::load ( const std::shared_ptr< SceneNode > &  target,
Uint64 *  state 
)
overridevirtual

Prepares a target for action

The important state of the target is stored in the given state parameter. The semantics of this state is action-dependent.

Parameters
targetThe node to act on
stateThe relevant node state

Reimplemented from cugl::scene2::Action.

◆ setSequence() [1/2]

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

Parameters
framesthe sequence of frames used in this animation

◆ setSequence() [2/2]

void cugl::scene2::Animate::setSequence ( const std::vector< int > &  frames,
const std::vector< float > &  time 
)

Sets the sequence of frames used in this animation

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

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

Parameters
framesthe sequence of frames used in this animation
timethe time to devote animating each frame

◆ setUniform()

void cugl::scene2::Animate::setUniform ( )

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

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

◆ toString()

virtual std::string cugl::scene2::Animate::toString ( bool  verbose = false) const
overridevirtual

Returns a string representation of the action for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this action for debuggging purposes.

Reimplemented from cugl::scene2::Action.

◆ update()

virtual void cugl::scene2::Animate::update ( const std::shared_ptr< SceneNode > &  target,
Uint64 *  state,
float  dt 
)
overridevirtual

Executes an action on the given target node.

The important state of the target is stored in the given state parameter. The semantics of this state is action-dependent.

Parameters
targetThe node to act on
stateThe relevant node state
dtThe elapsed time to animate.

Reimplemented from cugl::scene2::Action.

Member Data Documentation

◆ _frameset

std::vector<int> cugl::scene2::Animate::_frameset
protected

The list of frames to animate

◆ _timestep

std::vector<float> cugl::scene2::Animate::_timestep
protected

The amount of time for each frame

◆ _uniform

bool cugl::scene2::Animate::_uniform
protected

Whether or not the timestep is uniform


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