CUGL 1.3
Cornell University Game Library
CUFadeAction.h
1 //
2 // CUFadeAction.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for the fading actions. This includes fading
6 // in and out. Because they are absolute notions, these actions have no
7 // addition state to them (as is the case with other actions)
8 //
9 // These classes use 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 and Walker White
40 // Version: 3/12/17
41 //
42 #ifndef __CU_FADE_ACTION_H__
43 #define __CU_FADE_ACTION_H__
44 
45 #include "CUAction.h"
46 
47 namespace cugl {
48 
67 class FadeOut : public Action {
68 public:
69 #pragma mark Constructors
70 
76  FadeOut() {}
77 
81  ~FadeOut() { dispose(); }
82 
88  void dispose() {}
89 
99  bool init() {
100  return init(0.0f);
101  }
102 
115  bool init(float time);
116 
117 #pragma mark Static Constructors
118 
127  static std::shared_ptr<FadeOut> alloc() {
128  std::shared_ptr<FadeOut> result = std::make_shared<FadeOut>();
129  return (result->init() ? result : nullptr);
130  }
131 
144  static std::shared_ptr<FadeOut> alloc(float time) {
145  std::shared_ptr<FadeOut> result = std::make_shared<FadeOut>();
146  return (result->init(time) ? result : nullptr);
147  }
148 
149 #pragma mark Animation Methods
150 
155  virtual std::shared_ptr<Action> clone() override;
156 
166  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
167 
178  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
179 
180 #pragma mark Debugging Methods
181 
191  virtual std::string toString(bool verbose = false) const override;
192 };
193 
194 
195 #pragma mark -
196 
214 class FadeIn : public Action {
215 public:
216 #pragma mark Constructors
217 
223  FadeIn() {}
224 
228  ~FadeIn() { dispose(); }
229 
235  void dispose() {}
236 
246  bool init() {
247  return init(0.0f);
248  }
249 
262  bool init(float time);
263 
264 #pragma mark Static Constructors
265 
274  static std::shared_ptr<FadeIn> alloc() {
275  std::shared_ptr<FadeIn> result = std::make_shared<FadeIn>();
276  return (result->init() ? result : nullptr);
277  }
278 
291  static std::shared_ptr<FadeOut> alloc(float time) {
292  std::shared_ptr<FadeOut> result = std::make_shared<FadeOut>();
293  return (result->init(time) ? result : nullptr);
294  }
295 
296 #pragma mark Animation Methods
297 
302  virtual std::shared_ptr<Action> clone() override;
303 
313  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
314 
325  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
326 
327 #pragma mark Debugging Methods
328 
338  virtual std::string toString(bool verbose = false) const override;
339 };
340 
341 }
342 
343 #endif /* CUFadeAction_h */
cugl::FadeIn::~FadeIn
~FadeIn()
Definition: CUFadeAction.h:228
cugl::Action
Definition: CUAction.h:70
cugl::FadeOut::clone
virtual std::shared_ptr< Action > clone() override
cugl::FadeIn::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::FadeIn::toString
virtual std::string toString(bool verbose=false) const override
cugl::FadeIn::alloc
static std::shared_ptr< FadeIn > alloc()
Definition: CUFadeAction.h:274
cugl::FadeOut::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::FadeOut::dispose
void dispose()
Definition: CUFadeAction.h:88
cugl::FadeIn::FadeIn
FadeIn()
Definition: CUFadeAction.h:223
cugl::FadeIn::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::FadeIn::init
bool init()
Definition: CUFadeAction.h:246
cugl::FadeIn
Definition: CUFadeAction.h:214
cugl::FadeOut::toString
virtual std::string toString(bool verbose=false) const override
cugl::FadeOut
Definition: CUFadeAction.h:67
cugl::FadeOut::FadeOut
FadeOut()
Definition: CUFadeAction.h:76
cugl::FadeIn::alloc
static std::shared_ptr< FadeOut > alloc(float time)
Definition: CUFadeAction.h:291
cugl::FadeOut::~FadeOut
~FadeOut()
Definition: CUFadeAction.h:81
cugl::FadeIn::clone
virtual std::shared_ptr< Action > clone() override
cugl::FadeOut::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::FadeOut::alloc
static std::shared_ptr< FadeOut > alloc(float time)
Definition: CUFadeAction.h:144
cugl::FadeIn::dispose
void dispose()
Definition: CUFadeAction.h:235
cugl::FadeOut::alloc
static std::shared_ptr< FadeOut > alloc()
Definition: CUFadeAction.h:127
cugl::FadeOut::init
bool init()
Definition: CUFadeAction.h:99