From d8d7963b9b658799b806d516bbd6b44c4baa28f8 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 24 Oct 2018 22:08:46 +0800 Subject: =?UTF-8?q?+=E7=B2=92=E5=AD=90=E7=B3=BB=E7=BB=9F=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Graphics/animation/je_animation.h | 40 +++++++++++++--------- src/libjin/Graphics/animation/je_animator.cpp | 0 src/libjin/Graphics/animation/je_animator.h | 48 +++++++++++++++++++++++++++ src/libjin/Graphics/animation/je_clip.cpp | 0 src/libjin/Graphics/animation/je_clip.h | 44 ------------------------ 5 files changed, 72 insertions(+), 60 deletions(-) create mode 100644 src/libjin/Graphics/animation/je_animator.cpp create mode 100644 src/libjin/Graphics/animation/je_animator.h delete mode 100644 src/libjin/Graphics/animation/je_clip.cpp delete mode 100644 src/libjin/Graphics/animation/je_clip.h (limited to 'src/libjin/Graphics/animation') diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h index ca5758f..aa4c93f 100644 --- a/src/libjin/Graphics/animation/je_animation.h +++ b/src/libjin/Graphics/animation/je_animation.h @@ -1,11 +1,10 @@ #ifndef __JE_ANIMATION_H #define __JE_ANIMATION_H -#include #include #include -#include "je_clip.h" +#include "../je_sprite.h" namespace JinEngine { @@ -13,32 +12,41 @@ namespace JinEngine { /// - /// + /// Animation clip with key. /// class Animation { public: - void addClip(const std::string& key, Clip* clip); - bool hasKey(const std::string& key); + void onUpdate(float dt); - void play(); - void switchClipByKey(const std::string& key); - void switchClip(const Clip* clip); + void start(); + void pause(); + void stop(); + void rewind(); + void setSpeed(float speed); /// - /// Control clips. + /// Get current frame index. /// - void stopClip(); - void pauseClip(); - void rewindClip(); - void startClip(); + uint getCurrentFrame(); + + /// + /// Set current frame index. + /// + /// @param frame Current frame to play. + /// + void setCurrentFrame(uint frame); private: /// - /// Map a key to clips. + /// Key frames. + /// + std::vector mFrames; + + /// + /// Animation playing speed. /// - std::map mClips; - Clip* mCurrentClip; + float mSpeed; }; diff --git a/src/libjin/Graphics/animation/je_animator.cpp b/src/libjin/Graphics/animation/je_animator.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libjin/Graphics/animation/je_animator.h b/src/libjin/Graphics/animation/je_animator.h new file mode 100644 index 0000000..973ff58 --- /dev/null +++ b/src/libjin/Graphics/animation/je_animator.h @@ -0,0 +1,48 @@ +#ifndef __JE_ANIMATOR_H +#define __JE_ANIMATOR_H + +#include +#include +#include + +#include "je_animation.h" + +namespace JinEngine +{ + namespace Graphics + { + + /// + /// + /// + class Animator + { + public: + void addAnimation(const std::string& key, Animation* clip); + bool hasKey(const std::string& key); + + void play(); + void switchAnimationByKey(const std::string& key); + void switchAnimation(const Animation* clip); + + /// + /// Control clips. + /// + void stopAnimation(); + void pauseAnimation(); + void rewindAnimation(); + void startAnimation(); + + private: + /// + /// Map a key to clips. + /// + std::map mAnimations; + Animation* mCurrentAnimation; + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Graphics/animation/je_clip.cpp b/src/libjin/Graphics/animation/je_clip.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h deleted file mode 100644 index 6b6b0df..0000000 --- a/src/libjin/Graphics/animation/je_clip.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __JE_CLIP_H -#define __JE_CLIP_H - -#include -#include - -#include "../je_sprite.h" - -namespace JinEngine -{ - namespace Graphics - { - - /// - /// Animation clip with key. - /// - class Clip - { - public: - void onUpdate(float dt); - - void start(); - void pause(); - void stop(); - void rewind(); - void setSpeed(float speed); - - private: - /// - /// Key frames. - /// - std::vector mFrames; - - /// - /// Clip playing speed. - /// - float mSpeed; - - }; - - } // namespace Graphics -} // namespace JinEngine - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0