-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFiniteTimeActions.hpp
152 lines (130 loc) · 4 KB
/
FiniteTimeActions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// FiniteTimeActions.hpp
// Maw Kit
//
// Created by Lluís Ulzurrun de Asanza Sàez on 21/02/16.
//
//
#ifndef FiniteTimeActions_hpp
#define FiniteTimeActions_hpp
#include "cocos2d.h"
namespace MK {
/**
* `Actions` namespace offers useful extra `FiniteTimeActions`.
*/
namespace Actions {
/// `RemoveFromParent` action removes a node from its parent after certain
/// delay.
class RemoveFromParent : public cocos2d::ActionInterval {
public:
/**
* Creates an action that will remove a node from its parent after certain
* delay.
*
* @param duration Seconds to wait before removing node from parent.
*
* @return An autoreleased `RemoveFromParent` object.
*/
static RemoveFromParent *create( float duration );
//
// Overrides
//
virtual RemoveFromParent *clone() const override;
virtual RemoveFromParent *reverse( void ) const override;
virtual void startWithTarget( cocos2d::Node *target ) override;
virtual void update( float time ) override;
CC_CONSTRUCTOR_ACCESS : RemoveFromParent();
virtual ~RemoveFromParent();
/**
* Initializes the action with given duration.
*
* @param duration Duration in seconds
*
* @return Whether this instance could be initialized properly or not.
*/
bool initWithDuration( float duration );
private:
CC_DISALLOW_COPY_AND_ASSIGN( RemoveFromParent );
};
/// `Shake` action shakes a node during a certain delay.
class Shake : public cocos2d::Sequence {
public:
/**
* Creates a shake action with given duration and strength (maximum
* movement allowed).
*
* @param duration Duration in seconds of the animation.
* @param strength Maximum angle node will be rotated.
*
* @return An autoreleased `Shake` object.
*/
static cocos2d::Sequence *create( float duration, float strength = 10 );
private:
CC_DISALLOW_COPY_AND_ASSIGN( Shake );
};
/// `LinealShake` action shakes a node during a certain delay in one axis.
class LinealShake : public cocos2d::Sequence {
public:
/**
* Creates a lineal shake action with given duration and strength
* (maximum movement allowed in given axis).
*
* @param duration Duration in seconds of the animation.
* @param x_strength Maximum distance node will be moved in X axis.
* @param y_strength Maximum distance node will be moved in Y axis.
* @param z_strength Maximum distance node will be moved in Z axis.
*
* @return An autoreleased `LinealShake` object.
*/
static cocos2d::Sequence *
create( float duration, float x_strength = 0, float y_strength = 0, float z_strength = 0 );
private:
CC_DISALLOW_COPY_AND_ASSIGN( LinealShake );
};
/// `MoveToNode` action moves a node from its original location to the
/// location of given node, supporting moving to a node in movement.
class MoveToNode : public cocos2d::ActionInterval {
public:
/**
* Creates an action that will move a node to the position of given
* node.
*
* @param duration Duration of the animation.
* @param destinationNode Destination node.
*
* @return An autoreleased `MoveToNode` object.
*/
static MoveToNode *create( float duration, cocos2d::Node *destinationNode );
//
// Overrides
//
virtual MoveToNode *clone() const override;
virtual MoveToNode *reverse( void ) const override;
virtual void startWithTarget( cocos2d::Node *target ) override;
virtual void update( float time ) override;
CC_CONSTRUCTOR_ACCESS : MoveToNode();
virtual ~MoveToNode();
/**
* Initializes the action with given duration.
*
* @param duration Duration of the animation.
* @param destinationNode Destination node.
*
* @return Whether this instance could be initialized properly or not.
*/
bool initWithDuration( float duration, cocos2d::Node *destinationNode );
protected:
/**
* Node to be reached at the end of the animation.
*/
cocos2d::Node *destinationNode;
/**
* Original position of node to move.
*/
cocos2d::Point originalPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN( MoveToNode );
};
}; // namespace Actions
}; // namespace MK
#endif /* FiniteTimeActions_hpp */