![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUActionTimeline.h>
Public Member Functions | |
ActionTimeline () | |
~ActionTimeline () | |
void | dispose () |
bool | init () |
bool | add (const std::string key, ActionFunction action, float duration) |
bool | add (const std::string key, const std::shared_ptr< Action > &action, float duration) |
bool | add (const std::string key, ActionFunction action, float duration, EasingFunction easing) |
bool | add (const std::string key, const std::shared_ptr< Action > &action, float duration, EasingFunction easing) |
bool | remove (const std::string key) |
void | update (float dt) |
bool | isActive (const std::string key) const |
Uint32 | addListener (const std::string key, float time, ActionListener listener) |
Uint32 | addCompletionListener (const std::string key, ActionListener listener) |
const ActionListener | getListener (Uint32 key) const |
bool | removeListener (Uint32 key) |
float | getElapsed (const std::string key) const |
bool | isPaused (const std::string key) |
void | pause (const std::string key) |
void | unpause (const std::string key) |
Static Public Member Functions | |
static std::shared_ptr< ActionTimeline > | alloc () |
Friends | |
class | ActionInstance |
This class provides an timeline for managing active animations.
Because we do not want to force the users to define hash functions for their actions, actions are attached to the timeline via a key. This key allows the user to pause an action or query when it is complete. With each call to update
frame, this class moves the each action further along the timeline it is complete.
The timeline can only have one action for each key. However, it has no way preventing the user from assigning the same action to different keys. This is discouraged as the behavior in this case is undefined.
It is possible to assign listeners to each action to monitor its progress. As with the rest of our input listeners, attached listeners are assigned a key when they are attached, which can be used to remove them from the timeline. With that said, listeners are automatically removed when their associated action is complete.
|
inline |
Creates a new degenerate timeline 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 timeline, disposing all resources
|
inline |
Adds an action with the given duration.
The action will be invoked at the next call to update
.
This method will fail if the provided key is already in use.
key | The identifying key |
action | The action to animate |
duration | The action duration |
bool cugl::ActionTimeline::add | ( | const std::string | key, |
ActionFunction | action, | ||
float | duration, | ||
EasingFunction | easing | ||
) |
Adds an action with the given duration and easing function
The action will be invoked at the next call to update
. 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 |
duration | The action duration |
easing | The easing (interpolation) function |
|
inline |
Adds an action with the given duration.
The action will be invoked at the next call to update
.
This method will fail if the provided key is already in use.
key | The identifying key |
action | The action to animate |
duration | The action duration |
bool cugl::ActionTimeline::add | ( | const std::string | key, |
const std::shared_ptr< Action > & | action, | ||
float | duration, | ||
EasingFunction | easing | ||
) |
Actives an animation with the given action and easing function
The action will be invoked at the next call to update
. 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 |
duration | The action duration |
easing | The easing (interpolation) function |
Uint32 cugl::ActionTimeline::addCompletionListener | ( | const std::string | key, |
ActionListener | listener | ||
) |
Adds a listener for action completion.
This listener will be invoked when action is completed, just before it is removed from this timeline. This method is the same as calling addListener
with a time greater than the duration.
If there is no action for the given key, this method will return 0, indicating failure.
key | The key identifying the action |
listener | The listener to add |
Uint32 cugl::ActionTimeline::addListener | ( | const std::string | key, |
float | time, | ||
ActionListener | listener | ||
) |
Adds a listener for the specified action at the given time.
This listener will be invoked when the timeline first passes the given time for the specified object. Due to framerate imprecision, the actual time the listener is invoked may be slightly greater than the time requested.
If time is greater than or equal to the duration of action, this listener will be invoked once the action is completed. If it is less than or equal to 0, it will be invoked once the action is started.
If there is no action for the given key, this method will return 0, indicating failure.
key | The key identifying the action |
time | The invocation time |
listener | The listener to add |
|
inlinestatic |
Returns a newly allocated timeline.
The timeline will have no attached actions and will have an initial getElapsed
of 0.
void cugl::ActionTimeline::dispose | ( | ) |
Disposes all of the resources used by this timeline.
A disposed action manager can be safely reinitialized. Any animations owned by this action manager will immediately stop and be released.
float cugl::ActionTimeline::getElapsed | ( | const std::string | key | ) | const |
Returns the elapsed time of the given action.
If there is no animation for the give key (e.g. the animation is complete) this method will return 0.
key | The identifying key |
const ActionListener cugl::ActionTimeline::getListener | ( | Uint32 | key | ) | const |
Returns the action listener for the given key
If there is no listener for the given key, it returns nullptr.
key | The identifier for the listener |
|
inline |
Initializes a new timeline.
The timeline will have no attached actions and will have an initial getElapsed
of 0.
bool cugl::ActionTimeline::isActive | ( | const std::string | key | ) | const |
Returns true if the given key represents an active action
Note that paused actions are still active, even though they are paused.
key | The identifying key |
bool cugl::ActionTimeline::isPaused | ( | const 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::ActionTimeline::pause | ( | const 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 |
bool cugl::ActionTimeline::remove | ( | const std::string | key | ) |
Removes the action for the given key.
This method will immediately stop the animation. In particular, it will invoke any listeners waiting on completion.
If there is no animation for the give key (e.g. the animation is complete) this method will return false.
key | The identifying key |
bool cugl::ActionTimeline::removeListener | ( | Uint32 | key | ) |
Removes the action listener for the given key
If there is no active listener for the given key, this method fails and returns false.
key | The identifier for the listener |
void cugl::ActionTimeline::unpause | ( | const 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::ActionTimeline::update | ( | float | dt | ) |
Updates all non-paused actions by dt seconds
Each action is moved forward by dt seconds. If this causes an action to reach its duration, the action is removed and the key is once again available.
dt | The number of seconds to animate |