WoopsiGfx 1.4
Nintendo DS 2D Graphics Library
|
00001 #ifndef _ANIMATION_H_ 00002 #define _ANIMATION_H_ 00003 00004 #include <nds.h> 00005 #include "woopsiarray.h" 00006 00007 namespace WoopsiGfx { 00008 00009 class BitmapBase; 00010 00014 class Animation { 00015 public: 00016 00020 enum Status { 00021 ANIMATION_STATUS_STOPPED = 0, 00022 ANIMATION_STATUS_PLAYING = 1, 00023 ANIMATION_STATUS_PAUSED = 2 00024 }; 00025 00029 enum LoopType { 00030 ANIMATION_LOOPTYPE_NONE = 0, 00031 ANIMATION_LOOPTYPE_LOOP = 1, 00032 ANIMATION_LOOPTYPE_PINGPONG = 2 00033 }; 00034 00038 typedef struct { 00039 const BitmapBase* bitmap; 00040 u8 delay; 00041 } AnimFrame; 00042 00050 Animation(const u8 speed, const LoopType loopType, const u16 loops); 00051 00055 inline ~Animation() { }; 00056 00061 inline const AnimFrame* getCurrentFrame() const { 00062 return _frames.size() > 0 ? &_frames[_currentFrame] : NULL; 00063 }; 00064 00069 inline const BitmapBase* getCurrentBitmap() const { 00070 return _frames.size() > 0 ? _frames[_currentFrame].bitmap : NULL; 00071 }; 00072 00077 inline const Status getStatus() const { return _status; }; 00078 00083 inline const u8 getSpeed() const { return _speed; }; 00084 00089 inline const LoopType getLoopType() const { return _loopType; }; 00090 00096 inline const u16 getTimeToNextFrame() const { return _frameTimer; }; 00097 00102 inline const u16 getFrameCount() const { return _frames.size(); }; 00103 00108 inline void setSpeed(const u8 speed) { _speed = speed; }; 00109 00114 inline void setLoopType(const LoopType loopType) { _loopType = loopType; }; 00115 00122 void addFrame(const BitmapBase* bitmap, const u8 delay); 00123 00127 void run(); 00128 00132 void play(); 00133 00138 void stop(); 00139 00143 inline void pause() { _status = ANIMATION_STATUS_PAUSED; } 00144 00149 void goToFrame(u16 frame); 00150 00151 private: 00152 WoopsiArray<AnimFrame> _frames; 00153 u8 _speed; 00154 u16 _frameTimer; 00155 u16 _currentFrame; 00156 s8 _frameInc; 00157 u16 _requestedLoops; 00158 u16 _loopCount; 00160 LoopType _loopType; 00161 Status _status; 00167 bool loop(); 00168 }; 00169 } 00170 00171 #endif