CUGL 2.1
Cornell University Game Library
|
#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< ActionManager > | alloc () |
Protected Attributes | |
std::unordered_map< SceneNode *, std::unordered_set< std::string > > | _keys |
std::unordered_map< std::string, ActionInstance * > | _actions |
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.
|
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.
|
inline |
Deletes this action manager, disposing all resources
|
inline |
Actives an animation with the given target and action
This method will fail if the provided key is already in use.
key | The identifying key |
action | The action to animate with |
target | The node to animate on |
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.
key | The identifying key |
action | The action to animate with |
target | The node to animate on |
easing | The easing (interpolation) function |
|
inlinestatic |
Returns a newly allocated action manager.
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.
target | The node to stop animating |
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.
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.
target | The node to query animations |
|
inline |
Initializes an action manager.
bool cugl::scene2::ActionManager::isActive | ( | std::string | key | ) | const |
Returns true if the given key represents an active animation
key | The identifying key |
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.
key | The identifying key |
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.
key | The identifying key |
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.
target | The node to pause animating |
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.
key | The identifying key |
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.
key | The identifying key |
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.
target | The node to pause animating |
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.
dt | The number of seconds to animate |
|
protected |
A map that associates keys with animations
|
protected |
A map that associates nodes with their (multiple) animations