CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUAnimateAction.h
1 //
2 // CUAnimateAction.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for filmstrip animation. The animation is
6 // is represented as a sequence of frames. There is no tweening support
7 // between animation frames.
8 //
9 // This class uses our standard shared-pointer architecture.
10 //
11 // 1. The constructor does not perform any initialization; it just sets all
12 // attributes to their defaults.
13 //
14 // 2. All initialization takes place via init methods, which can fail if an
15 // object is initialized more than once.
16 //
17 // 3. All allocation takes place via static constructors which return a shared
18 // pointer.
19 //
20 // CUGL MIT License:
21 // This software is provided 'as-is', without any express or implied
22 // warranty. In no event will the authors be held liable for any damages
23 // arising from the use of this software.
24 //
25 // Permission is granted to anyone to use this software for any purpose,
26 // including commercial applications, and to alter it and redistribute it
27 // freely, subject to the following restrictions:
28 //
29 // 1. The origin of this software must not be misrepresented; you must not
30 // claim that you wrote the original software. If you use this software
31 // in a product, an acknowledgment in the product documentation would be
32 // appreciated but is not required.
33 //
34 // 2. Altered source versions must be plainly marked as such, and must not
35 // be misrepresented as being the original software.
36 //
37 // 3. This notice may not be removed or altered from any source distribution.
38 //
39 // Author: Sophie Huang
40 // Version: 11/1/16
41 
42 #ifndef __CU_ANIMATE_ACTION_H__
43 #define __CU_ANIMATE_ACTION_H__
44 
45 #include "CUAction.h"
46 
47 namespace cugl {
48 
67 class Animate : public Action {
68 protected:
70  std::vector<int> _frameset;
72  std::vector<float> _timestep;
74  bool _uniform;
75 
76 public:
77 #pragma mark Constructors
78 
84  Animate() : _uniform(true) {}
85 
89  ~Animate() { dispose(); }
90 
96  void dispose();
97 
105  bool init() { return true; }
106 
126  bool init(int start, int end, float time, int repeat = 1);
127 
140  bool init(const std::vector<int>& frames, float time);
141 
156  bool init(const std::vector<int>& frames, const std::vector<float>& time);
157 
158 
159 #pragma mark Static Constructors
160 
167  static std::shared_ptr<Animate> alloc() {
168  std::shared_ptr<Animate> result = std::make_shared<Animate>();
169  return (result->init() ? result : nullptr);
170  }
171 
191  static std::shared_ptr<Animate> alloc(int start, int end, float time, int repeat = 1) {
192  std::shared_ptr<Animate> result = std::make_shared<Animate>();
193  return (result->init(start,end,time,repeat) ? result : nullptr);
194  }
195 
208  static std::shared_ptr<Animate> alloc(const std::vector<int>& frames, float time) {
209  std::shared_ptr<Animate> result = std::make_shared<Animate>();
210  return (result->init(frames,time) ? result : nullptr);
211  }
212 
227  static std::shared_ptr<Animate> alloc(const std::vector<int>& frames, const std::vector<float>& time) {
228  std::shared_ptr<Animate> result = std::make_shared<Animate>();
229  return (result->init(frames,time) ? result : nullptr);
230  }
231 
232 #pragma mark Atributes
233 
238  int getFrame(float t) const;
239 
248  const std::vector<int>& getSequence() const { return _frameset; }
249 
261  const std::vector<float>& getTimeSteps() const { return _timestep; }
262 
275  void setSequence(const std::vector<int>& frames);
276 
288  void setSequence(const std::vector<int>& frames, const std::vector<float>& time);
289 
298  int isUniform() const { return _uniform; }
299 
306  void setUniform();
307 
308 #pragma mark Animation Methods
309 
314  virtual std::shared_ptr<Action> clone() override;
315 
325  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
326 
337  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
338 
339 #pragma mark Debugging Methods
340 
350  virtual std::string toString(bool verbose = false) const override;
351 
352 };
353 
354 }
355 
356 #endif /* __CU_ANIMATE_ACTION_H__ */
cugl::Animate::init
bool init()
Definition: CUAnimateAction.h:105
cugl::Action
Definition: CUAction.h:70
cugl::Animate::_frameset
std::vector< int > _frameset
Definition: CUAnimateAction.h:70
cugl::Animate::dispose
void dispose()
cugl::Animate::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::Animate::alloc
static std::shared_ptr< Animate > alloc(const std::vector< int > &frames, float time)
Definition: CUAnimateAction.h:208
cugl::Animate::getFrame
int getFrame(float t) const
cugl::Animate::Animate
Animate()
Definition: CUAnimateAction.h:84
cugl::Animate::setUniform
void setUniform()
cugl::Animate::alloc
static std::shared_ptr< Animate > alloc(int start, int end, float time, int repeat=1)
Definition: CUAnimateAction.h:191
cugl::Animate::_uniform
bool _uniform
Definition: CUAnimateAction.h:74
cugl::Animate::toString
virtual std::string toString(bool verbose=false) const override
cugl::Animate::~Animate
~Animate()
Definition: CUAnimateAction.h:89
cugl::Animate::alloc
static std::shared_ptr< Animate > alloc(const std::vector< int > &frames, const std::vector< float > &time)
Definition: CUAnimateAction.h:227
cugl::Animate::getTimeSteps
const std::vector< float > & getTimeSteps() const
Definition: CUAnimateAction.h:261
cugl::Animate::isUniform
int isUniform() const
Definition: CUAnimateAction.h:298
cugl::Animate::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::Animate::getSequence
const std::vector< int > & getSequence() const
Definition: CUAnimateAction.h:248
cugl::Animate::_timestep
std::vector< float > _timestep
Definition: CUAnimateAction.h:72
cugl::Animate::clone
virtual std::shared_ptr< Action > clone() override
cugl::Animate::alloc
static std::shared_ptr< Animate > alloc()
Definition: CUAnimateAction.h:167
cugl::Animate::setSequence
void setSequence(const std::vector< int > &frames)
cugl::Animate
Definition: CUAnimateAction.h:67