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

#include <CUActionManager.h>

Public Member Functions

 ActionManager ()
 
 ~ActionManager ()
 
void dispose ()
 
bool init ()
 
bool isActive (std::string key) const
 
bool activate (std::string key, const std::shared_ptr< Action > &action, const std::shared_ptr< SceneNode > &target)
 
bool activate (std::string key, const std::shared_ptr< Action > &action, const std::shared_ptr< SceneNode > &target, std::function< float(float)> easing)
 
bool remove (std::string key)
 
void update (float dt)
 
bool isPaused (std::string key)
 
void pause (std::string key)
 
void unpause (std::string key)
 
void clearAllActions (const std::shared_ptr< SceneNode > &target)
 
void pauseAllActions (const std::shared_ptr< SceneNode > &target)
 
void unpauseAllActions (const std::shared_ptr< SceneNode > &target)
 
std::vector< std::string > getAllActions (const std::shared_ptr< SceneNode > &target) const
 

Static Public Member Functions

static std::shared_ptr< ActionManageralloc ()
 

Protected Attributes

std::unordered_map< SceneNode *, std::unordered_set< std::string > > _keys
 
std::unordered_map< std::string, ActionInstance * > _actions
 

Detailed Description

This class provides an action manager for instantiating animations.

To create an animation, the manager attaches an action to a scene graph node via a key. This key allows the user to pause an animation or query when it is complete. Each update frame, the manager moves the animation further along until it is complete.

An action manager is not implemented as a singleton. However, you typically only need one manager per application.

Constructor & Destructor Documentation

◆ ActionManager()

cugl::scene2::ActionManager::ActionManager ( )
inline

Creates a new degenerate ActionManager on the stack.

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

◆ ~ActionManager()

cugl::scene2::ActionManager::~ActionManager ( )
inline

Deletes this action manager, disposing all resources

Member Function Documentation

◆ activate() [1/2]

bool cugl::scene2::ActionManager::activate ( std::string  key,
const std::shared_ptr< Action > &  action,
const std::shared_ptr< SceneNode > &  target 
)
inline

Actives an animation with the given target and action

This method will fail if the provided key is already in use.

Parameters
keyThe identifying key
actionThe action to animate with
targetThe node to animate on
Returns
true if the animation was successfully started

◆ activate() [2/2]

bool cugl::scene2::ActionManager::activate ( std::string  key,
const std::shared_ptr< Action > &  action,
const std::shared_ptr< SceneNode > &  target,
std::function< float(float)>  easing 
)

Actives an animation with the given target and action

The easing function allows for effects like bouncing or elasticity in the linear interpolation. If null, the animation will use the standard linear easing.

This method will fail if the provided key is already in use.

Parameters
keyThe identifying key
actionThe action to animate with
targetThe node to animate on
easingThe easing (interpolation) function
Returns
true if the animation was successfully started

◆ alloc()

static std::shared_ptr<ActionManager> cugl::scene2::ActionManager::alloc ( )
inlinestatic

Returns a newly allocated action manager.

Returns
a newly allocated action manager.

◆ clearAllActions()

void cugl::scene2::ActionManager::clearAllActions ( const std::shared_ptr< SceneNode > &  target)

Removes all animations for the given target.

If the target has no associated animations, this method does nothing.

Parameters
targetThe node to stop animating

◆ dispose()

void cugl::scene2::ActionManager::dispose ( )

Disposes all of the resources used by this action manager.

A disposed action manager can be safely reinitialized. Any animations owned by this action manager will immediately stop and be released.

◆ getAllActions()

std::vector<std::string> cugl::scene2::ActionManager::getAllActions ( const std::shared_ptr< SceneNode > &  target) const

Returns the keys for all active animations of the given target

The returned vector is a copy of the keys. Modifying it has no affect on the underlying animation.

Parameters
targetThe node to query animations
Returns
the keys for all active animations of the given target

◆ init()

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

Initializes an action manager.

Returns
true if initialization was successful.

◆ isActive()

bool cugl::scene2::ActionManager::isActive ( std::string  key) const

Returns true if the given key represents an active animation

Parameters
keyThe identifying key
Returns
true if the given key represents an active animation

◆ isPaused()

bool cugl::scene2::ActionManager::isPaused ( std::string  key)

Returns true if the animation for the given key is paused

This method will return false if there is no active animation with the given key.

Parameters
keyThe identifying key
Returns
true if the animation for the given key is paused

◆ pause()

void cugl::scene2::ActionManager::pause ( std::string  key)

Pauses the animation for the given key.

If there is no active animation for the given key, or if it is already paused, this method does nothing.

Parameters
keyThe identifying key

◆ pauseAllActions()

void cugl::scene2::ActionManager::pauseAllActions ( const std::shared_ptr< SceneNode > &  target)

Pauses all animations for the given target.

If the target has no associated animations, or if all of its animations are already paused, this method does nothing.

Parameters
targetThe node to pause animating

◆ remove()

bool cugl::scene2::ActionManager::remove ( std::string  key)

Removes the animation for the given key.

This act will immediately stop the animation. The animated node will continue to have whatever state it had when the animation stopped.

If there is no animation for the give key (e.g. the animation is complete) this method will return false.

Parameters
keyThe identifying key
Returns
true if the animation was successfully removed

◆ unpause()

void cugl::scene2::ActionManager::unpause ( std::string  key)

Unpauses the animation for the given key.

If there is no active animation for the given key, or if it is not currently paused, this method does nothing.

Parameters
keyThe identifying key

◆ unpauseAllActions()

void cugl::scene2::ActionManager::unpauseAllActions ( const std::shared_ptr< SceneNode > &  target)

Unpauses all animations for the given target.

If the target has no associated animations, or if none of its animations are currenly paused, this method does nothing.

Parameters
targetThe node to pause animating

◆ update()

void cugl::scene2::ActionManager::update ( float  dt)

Updates all non-paused animations by dt seconds

Each animation is moved forward by dt second. If this causes an animation to reach its duration, the animation is removed and the key is once again available.

Parameters
dtThe number of seconds to animate

Member Data Documentation

◆ _actions

std::unordered_map<std::string, ActionInstance*> cugl::scene2::ActionManager::_actions
protected

A map that associates keys with animations

◆ _keys

std::unordered_map<SceneNode*, std::unordered_set<std::string> > cugl::scene2::ActionManager::_keys
protected

A map that associates nodes with their (multiple) animations


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