| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #ifndef ANIMATIONCONTROLLER_H_
- #define ANIMATIONCONTROLLER_H_
- #include "AnimationClip.h"
- #include "Animation.h"
- #include "AnimationTarget.h"
- namespace gameplay
- {
- /**
- * Defines a class for controlling game animation.
- */
- class AnimationController
- {
- friend class Game;
- friend class Animation;
- friend class AnimationClip;
- public:
- /**
- * Creates an animation on this target from a set of key value and key time pairs.
- * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
- *
- * @param id The ID of the animation.
- * @param target The animation target.
- * @param propertyId The property on this target to animate.
- * @param keyCount The number of keyframes in the animation. Must be greater than one.
- * @param keyTimes The list of key times for the animation (in milliseconds).
- * @param keyValues The list of key values for the animation.
- * @param type The curve interpolation type.
- *
- * @return The newly created animation, or NULL if an animation with the given ID already exists.
- */
- Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type);
- /**
- * Creates an animation on this target from a set of key value and key time pairs.
- *
- * @param id The ID of the animation.
- * @param target The animation target.
- * @param propertyId The property on this target to animate.
- * @param keyCount The number of keyframes in the animation. Must be greater than one.
- * @param keyTimes The list of key times for the animation (in milliseconds).
- * @param keyValues The list of key values for the animation.
- * @param keyInValue The list of key in values for the animation.
- * @param keyOutValue The list of key out values for the animation.
- * @param type The curve interpolation type.
- *
- * @return The newly created animation, or NULL if an animation with the given ID already exists.
- */
- Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type);
- /**
- * Creates a simple two keyframe from-to animation.
- * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
- *
- * @param id The ID of the animation.
- * @param target The animation target.
- * @param propertyId The property on this target to animate.
- * @param from The values to animate from.
- * @param to The values to animate to.
- * @param type The curve interpolation type.
- * @param duration The duration of the animation (in milliseconds).
- *
- * @return The newly created animation, or NULL if an animation with the given ID already exists.
- */
- Animation* createAnimationFromTo(const char* id, AnimationTarget* target, int propertyId, float* from, float* to, Curve::InterpolationType type, unsigned long duration);
- /**
- * Creates a simple two keyframe from-by animation.
- * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
- *
- * @param id The ID of the animation.
- * @param target The animation target.
- * @param propertyId The property on this target to animate.
- * @param from The values to animate from.
- * @param by The values to animate by.
- * @param type The curve interpolation type.
- * @param duration The duration of the animation (in milliseconds).
- *
- * @return The newly created animation, or NULL if an animation with the given ID already exists.
- */
- Animation* createAnimationFromBy(const char* id, AnimationTarget* target, int propertyId, float* from, float* by, Curve::InterpolationType type, unsigned long duration);
- /**
- * Finds the animation with the given ID.
- *
- * @param id The ID of the animation to get. NULL if the Animation is not found.
- *
- * @return The animation, or NULL if not found.
- */
- Animation* getAnimation(const char* id) const;
- /**
- * Stops all AnimationClips currently playing on the AnimationController.
- */
- void stopAllAnimations();
-
- private:
- enum State
- {
- RUNNING,
- IDLE,
- PAUSED
- };
- /**
- * Constructor.
- */
- AnimationController();
- /**
- * Constructor.
- */
- AnimationController(const AnimationController& copy);
- /**
- * Destructor.
- */
- ~AnimationController();
-
- /**
- * Gets the controller's state.
- *
- * @return The current state.
- */
- State getState() const;
- /**
- * Callback for when the controller is initialized.
- */
- void initialize();
- /*
- * Callback for when the controller is finalized.
- */
- void finalize();
- /**
- * Resumes the AnimationController.
- */
- void resume();
-
- /**
- * Pauses the AnimationController.
- */
- void pause();
- /**
- * Schedules an AnimationClip to run.
- */
- void schedule(AnimationClip* clip);
- /**
- * Unschedules an AnimationClip.
- */
- void unschedule(AnimationClip* clip);
-
- /**
- * Callback for when the controller receives a frame update event.
- */
- void update(long elapsedTime);
-
- /**
- * Adds an animation on this AnimationTarget.
- */
- void addAnimation(Animation* animation);
- /**
- * Removes the given animation from this AnimationTarget.
- */
- void destroyAnimation(Animation* animation);
- /**
- * Removes all animations from the AnimationTarget.
- */
- void destroyAllAnimations();
-
- State _state; // The current state of the AnimationController.
- std::list<AnimationClip*> _runningClips; // A list of currently running AnimationClips.
- std::vector<Animation*> _animations; // A list of animations registered with the AnimationController
- };
- }
- #endif
|