1 #ifndef UGDK_ACTION_ANIMATIONPLAYER_H_
2 #define UGDK_ACTION_ANIMATIONPLAYER_H_
23 : current_animation_(nullptr)
30 frame_change_callback_ = callback;
34 return current_animation_;
38 return *current_animation_->
frames()[current_frame_];
42 if (!current_animation_)
return;
46 if (elapsed_time_ >= frame_period) {
47 elapsed_time_ -= frame_period;
57 ExecuteFrameChangeCallback();
62 void Select(
const std::string& name) {
64 this->set_current_animation(table_->
Search(name));
71 this->set_current_animation(table_->
Get(index));
76 if (current_animation_)
77 ExecuteFrameChangeCallback();
88 void set_current_animation(
const Animation* anim) {
89 auto previous_anim = current_animation_;
90 current_animation_ = anim;
91 if (anim != previous_anim)
95 void ExecuteFrameChangeCallback() {
96 if (frame_change_callback_)
100 void ChangeToNextFrame() {
104 if(current_frame_ >= current_animation_->
frames().size()) {
114 ExecuteFrameChangeCallback();
116 if (notify && !notified_) {
const Frame & current_animation_frame() const
Definition: animationplayer.h:37
Definition: indexabletable.h:15
structure::IndexableTable< Animation > AnimationTable
Definition: animationplayer.h:19
const Animation * current_animation() const
Definition: animationplayer.h:33
Definition: animation.h:11
void Refresh()
Calls the frame changed callback with the current frame.
Definition: animationplayer.h:75
Definition: animationplayer.h:16
Vector & frames()
Definition: animation.h:31
T * Get(int index) const
Instant access to an element, using a pre-generated ID.
Definition: indexabletable.h:58
void RestartAnimation()
Restarts the current animation from the first frame.
Definition: animationplayer.h:53
AnimationPlayer(const AnimationTable *table)
Definition: animationplayer.h:22
void set_frame_change_callback(const FrameChangedCallback &callback)
Definition: animationplayer.h:29
Definition: animation.h:15
T * Search(const std::string &name) const
Searches for the element with the given name.
Definition: indexabletable.h:47
void Select(const std::string &name)
Change the current animation to a new animation from the previously selected AnimationSet.
Definition: animationplayer.h:62
std::function< void(const Frame &)> FrameChangedCallback
Definition: animationplayer.h:20
void Select(int index)
Change the current animation to a new animation from the previo2usly selected AnimationSet.
Definition: animationplayer.h:69
AnimationRepeat repeat() const
Definition: animation.h:34
void Update(double dt)
Definition: animationplayer.h:41