CCActionInterval.h
44.5 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __ACTION_CCINTERVAL_ACTION_H__
#define __ACTION_CCINTERVAL_ACTION_H__
#include <vector>
#include "2d/CCAction.h"
#include "2d/CCAnimation.h"
#include "base/CCProtocols.h"
#include "base/CCVector.h"
NS_CC_BEGIN
class Node;
class SpriteFrame;
class EventCustom;
/**
* @addtogroup actions
* @{
*/
/** @class ActionInterval
@brief An interval action is an action that takes place within a certain period of time.
It has an start time, and a finish time. The finish time is the parameter
duration plus the start time.
These ActionInterval actions have some interesting properties, like:
- They can run normally (default)
- They can run reversed with the reverse method
- They can run with the time altered with the Accelerate, AccelDeccel and Speed actions.
For example, you can simulate a Ping Pong effect running the action normally and
then running it again in Reverse mode.
Example:
@code
auto action = MoveBy::create(1.0f, Vec2::ONE);
auto pingPongAction = Sequence::create(action, action->reverse(), nullptr);
@endcode
*/
class CC_DLL ActionInterval : public FiniteTimeAction
{
public:
/** How many seconds had elapsed since the actions started to run.
*
* @return The seconds had elapsed since the actions started to run.
*/
float getElapsed() { return _elapsed; }
/** Sets the amplitude rate, extension in GridAction
*
* @param amp The amplitude rate.
*/
void setAmplitudeRate(float amp);
/** Gets the amplitude rate, extension in GridAction
*
* @return The amplitude rate.
*/
float getAmplitudeRate();
//
// Overrides
//
virtual bool isDone() const override;
/**
* @param dt in seconds
*/
virtual void step(float dt) override;
virtual void startWithTarget(Node *target) override;
virtual ActionInterval* reverse() const override
{
CC_ASSERT(0);
return nullptr;
}
virtual ActionInterval *clone() const override
{
CC_ASSERT(0);
return nullptr;
}
CC_CONSTRUCTOR_ACCESS:
/** initializes the action */
bool initWithDuration(float d);
protected:
float _elapsed;
bool _firstTick;
bool _done;
protected:
bool sendUpdateEventToScript(float dt, Action *actionObject);
};
/** @class Sequence
* @brief Runs actions sequentially, one after another.
*/
class CC_DLL Sequence : public ActionInterval
{
public:
/** Helper constructor to create an array of sequenceable actions.
*
* @return An autoreleased Sequence object.
*/
static Sequence* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
/** Helper constructor to create an array of sequenceable actions given an array.
* @code
* When this function bound to the js or lua,the input params changed
* in js :var create(var object1,var object2, ...)
* in lua :local create(local object1,local object2, ...)
* @endcode
*
* @param arrayOfActions An array of sequenceable actions.
* @return An autoreleased Sequence object.
*/
static Sequence* create(const Vector<FiniteTimeAction*>& arrayOfActions);
/** Helper constructor to create an array of sequence-able actions.
*
* @param action1 The first sequenceable action.
* @param args The va_list variable.
* @return An autoreleased Sequence object.
* @js NA
*/
static Sequence* createWithVariableList(FiniteTimeAction *action1, va_list args);
/** Creates the action.
* @param actionOne The first sequenceable action.
* @param actionTwo The second sequenceable action.
* @return An autoreleased Sequence object.
* @js NA
*/
static Sequence* createWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo);
//
// Overrides
//
virtual Sequence* clone() const override;
virtual Sequence* reverse() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
virtual bool isDone() const override;
/**
* @param t In seconds.
*/
virtual void update(float t) override;
CC_CONSTRUCTOR_ACCESS:
Sequence();
virtual ~Sequence();
/** initializes the action */
bool initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo);
bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
protected:
FiniteTimeAction *_actions[2];
float _split;
int _last;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Sequence);
};
/** @class Repeat
* @brief Repeats an action a number of times.
* To repeat an action forever use the RepeatForever action.
*/
class CC_DLL Repeat : public ActionInterval
{
public:
/** Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30).
*
* @param action The action needs to repeat.
* @param times The repeat times.
* @return An autoreleased Repeat object.
*/
static Repeat* create(FiniteTimeAction *action, unsigned int times);
/** Sets the inner action.
*
* @param action The inner action.
*/
void setInnerAction(FiniteTimeAction *action)
{
if (_innerAction != action)
{
CC_SAFE_RETAIN(action);
CC_SAFE_RELEASE(_innerAction);
_innerAction = action;
}
}
/** Gets the inner action.
*
* @return The inner action.
*/
FiniteTimeAction* getInnerAction()
{
return _innerAction;
}
//
// Overrides
//
virtual Repeat* clone() const override;
virtual Repeat* reverse() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
/**
* @param dt In seconds.
*/
virtual void update(float dt) override;
virtual bool isDone() const override;
CC_CONSTRUCTOR_ACCESS:
Repeat() {}
virtual ~Repeat();
/** initializes a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */
bool initWithAction(FiniteTimeAction *pAction, unsigned int times);
protected:
unsigned int _times;
unsigned int _total;
float _nextDt;
bool _actionInstant;
/** Inner action */
FiniteTimeAction *_innerAction;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Repeat);
};
/** @class RepeatForever
* @brief Repeats an action for ever.
To repeat the an action for a limited number of times use the Repeat action.
* @warning This action can't be Sequenceable because it is not an IntervalAction.
*/
class CC_DLL RepeatForever : public ActionInterval
{
public:
/** Creates the action.
*
* @param action The action need to repeat forever.
* @return An autoreleased RepeatForever object.
*/
static RepeatForever* create(ActionInterval *action);
/** Sets the inner action.
*
* @param action The inner action.
*/
void setInnerAction(ActionInterval *action)
{
if (_innerAction != action)
{
CC_SAFE_RELEASE(_innerAction);
_innerAction = action;
CC_SAFE_RETAIN(_innerAction);
}
}
/** Gets the inner action.
*
* @return The inner action.
*/
ActionInterval* getInnerAction()
{
return _innerAction;
}
//
// Overrides
//
virtual RepeatForever* clone() const override;
virtual RepeatForever* reverse() const override;
virtual void startWithTarget(Node* target) override;
/**
* @param dt In seconds.
*/
virtual void step(float dt) override;
virtual bool isDone() const override;
CC_CONSTRUCTOR_ACCESS:
RepeatForever()
: _innerAction(nullptr)
{}
virtual ~RepeatForever();
/** initializes the action */
bool initWithAction(ActionInterval *action);
protected:
/** Inner action */
ActionInterval *_innerAction;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RepeatForever);
};
/** @class Spawn
* @brief Spawn a new action immediately
*/
class CC_DLL Spawn : public ActionInterval
{
public:
/** Helper constructor to create an array of spawned actions.
* @code
* When this function bound to the js or lua, the input params changed.
* in js :var create(var object1,var object2, ...)
* in lua :local create(local object1,local object2, ...)
* @endcode
*
* @return An autoreleased Spawn object.
*/
static Spawn* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
/** Helper constructor to create an array of spawned actions.
*
* @param action1 The first sequenceable action.
* @param args The va_list variable.
* @return An autoreleased Spawn object.
* @js NA
*/
static Spawn* createWithVariableList(FiniteTimeAction *action1, va_list args);
/** Helper constructor to create an array of spawned actions given an array.
*
* @param arrayOfActions An array of spawned actions.
* @return An autoreleased Spawn object.
*/
static Spawn* create(const Vector<FiniteTimeAction*>& arrayOfActions);
/** Creates the Spawn action.
*
* @param action1 The first spawned action.
* @param action2 The second spawned action.
* @return An autoreleased Spawn object.
* @js NA
*/
static Spawn* createWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2);
//
// Overrides
//
virtual Spawn* clone() const override;
virtual Spawn* reverse() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
Spawn();
virtual ~Spawn();
/** initializes the Spawn action with the 2 actions to spawn */
bool initWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2);
bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
protected:
FiniteTimeAction *_one;
FiniteTimeAction *_two;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Spawn);
};
/** @class RotateTo
* @brief Rotates a Node object to a certain angle by modifying it's rotation attribute.
The direction will be decided by the shortest angle.
*/
class CC_DLL RotateTo : public ActionInterval
{
public:
/**
* Creates the action with separate rotation angles.
*
* @param duration Duration time, in seconds.
* @param dstAngleX In degreesCW.
* @param dstAngleY In degreesCW.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, float dstAngleX, float dstAngleY);
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param dstAngle In degreesCW.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, float dstAngle);
/**
* Creates the action with 3D rotation angles.
* @param duration Duration time, in seconds.
* @param dstAngle3D A Vec3 angle.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, const Vec3& dstAngle3D);
//
// Overrides
//
virtual RotateTo* clone() const override;
virtual RotateTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
RotateTo();
virtual ~RotateTo() {}
/**
* initializes the action
* @param duration in seconds
* @param dstAngleX in degreesCW
* @param dstAngleY in degreesCW
*/
bool initWithDuration(float duration, float dstAngleX, float dstAngleY);
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec3& dstAngle3D);
/**
* calculates the start and diff angles
* @param dstAngle in degreesCW
*/
void calculateAngles(float &startAngle, float &diffAngle, float dstAngle);
protected:
bool _is3D;
Vec3 _dstAngle;
Vec3 _startAngle;
Vec3 _diffAngle;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RotateTo);
};
/** @class RotateBy
* @brief Rotates a Node object clockwise a number of degrees by modifying it's rotation attribute.
*/
class CC_DLL RotateBy : public ActionInterval
{
public:
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaAngle In degreesCW.
* @return An autoreleased RotateBy object.
*/
static RotateBy* create(float duration, float deltaAngle);
/**
* Creates the action with separate rotation angles.
*
* @param duration Duration time, in seconds.
* @param deltaAngleZ_X In degreesCW.
* @param deltaAngleZ_Y In degreesCW.
* @return An autoreleased RotateBy object.
* @warning The physics body contained in Node doesn't support rotate with different x and y angle.
*/
static RotateBy* create(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
/** Creates the action with 3D rotation angles.
*
* @param duration Duration time, in seconds.
* @param deltaAngle3D A Vec3 angle.
* @return An autoreleased RotateBy object.
*/
static RotateBy* create(float duration, const Vec3& deltaAngle3D);
//
// Override
//
virtual RotateBy* clone() const override;
virtual RotateBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
RotateBy();
virtual ~RotateBy() {}
/** initializes the action */
bool initWithDuration(float duration, float deltaAngle);
/**
* @warning The physics body contained in Node doesn't support rotate with different x and y angle.
* @param deltaAngleZ_X in degreesCW
* @param deltaAngleZ_Y in degreesCW
*/
bool initWithDuration(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
bool initWithDuration(float duration, const Vec3& deltaAngle3D);
protected:
bool _is3D;
Vec3 _deltaAngle;
Vec3 _startAngle;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RotateBy);
};
/** @class MoveBy
* @brief Moves a Node object x,y pixels by modifying it's position attribute.
x and y are relative to the position of the object.
Several MoveBy actions can be concurrently called, and the resulting
movement will be the sum of individual movements.
@since v2.1beta2-custom
*/
class CC_DLL MoveBy : public ActionInterval
{
public:
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaPosition The delta distance in 2d, it's a Vec2 type.
* @return An autoreleased MoveBy object.
*/
static MoveBy* create(float duration, const Vec2& deltaPosition);
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaPosition The delta distance in 3d, it's a Vec3 type.
* @return An autoreleased MoveBy object.
*/
static MoveBy* create(float duration, const Vec3& deltaPosition);
//
// Overrides
//
virtual MoveBy* clone() const override;
virtual MoveBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time in seconds
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
MoveBy():_is3D(false) {}
virtual ~MoveBy() {}
/** initializes the action */
bool initWithDuration(float duration, const Vec2& deltaPosition);
bool initWithDuration(float duration, const Vec3& deltaPosition);
protected:
bool _is3D;
Vec3 _positionDelta;
Vec3 _startPosition;
Vec3 _previousPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(MoveBy);
};
/** @class MoveTo
* @brief Moves a Node object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.
Several MoveTo actions can be concurrently called, and the resulting
movement will be the sum of individual movements.
@since v2.1beta2-custom
*/
class CC_DLL MoveTo : public MoveBy
{
public:
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The destination position in 2d.
* @return An autoreleased MoveTo object.
*/
static MoveTo* create(float duration, const Vec2& position);
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The destination position in 3d.
* @return An autoreleased MoveTo object.
*/
static MoveTo* create(float duration, const Vec3& position);
//
// Overrides
//
virtual MoveTo* clone() const override;
virtual MoveTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
CC_CONSTRUCTOR_ACCESS:
MoveTo() {}
virtual ~MoveTo() {}
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec2& position);
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec3& position);
protected:
Vec3 _endPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(MoveTo);
};
/** @class SkewTo
* @brief Skews a Node object to given angles by modifying it's skewX and skewY attributes
@since v1.0
*/
class CC_DLL SkewTo : public ActionInterval
{
public:
/**
* Creates the action.
* @param t Duration time, in seconds.
* @param sx Skew x angle.
* @param sy Skew y angle.
* @return An autoreleased SkewTo object.
*/
static SkewTo* create(float t, float sx, float sy);
//
// Overrides
//
virtual SkewTo* clone() const override;
virtual SkewTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
SkewTo();
virtual ~SkewTo() {}
/**
* @param t In seconds.
*/
bool initWithDuration(float t, float sx, float sy);
protected:
float _skewX;
float _skewY;
float _startSkewX;
float _startSkewY;
float _endSkewX;
float _endSkewY;
float _deltaX;
float _deltaY;
private:
CC_DISALLOW_COPY_AND_ASSIGN(SkewTo);
};
/** @class SkewBy
* @brief Skews a Node object by skewX and skewY degrees.
@since v1.0
*/
class CC_DLL SkewBy : public SkewTo
{
public:
/**
* Creates the action.
* @param t Duration time, in seconds.
* @param deltaSkewX Skew x delta angle.
* @param deltaSkewY Skew y delta angle.
* @return An autoreleased SkewBy object.
*/
static SkewBy* create(float t, float deltaSkewX, float deltaSkewY);
//
// Overrides
//
virtual void startWithTarget(Node *target) override;
virtual SkewBy* clone() const override;
virtual SkewBy* reverse() const override;
CC_CONSTRUCTOR_ACCESS:
SkewBy() {}
virtual ~SkewBy() {}
/**
* @param t In seconds.
*/
bool initWithDuration(float t, float sx, float sy);
private:
CC_DISALLOW_COPY_AND_ASSIGN(SkewBy);
};
/** @class ResizeTo
* @brief Resize a Node object to the final size by modifying it's Size attribute.
*/
class CC_DLL ResizeTo : public ActionInterval
{
public:
/**
* Creates the action.
* @brief Resize a Node object to the final size by modifying it's Size attribute. Works on all nodes where setContentSize is effective. But it's mostly useful for nodes where 9-slice is enabled
* @param duration Duration time, in seconds.
* @param final_size The target size to reach
* @return An autoreleased RotateTo object.
*/
static ResizeTo* create(float duration, const cocos2d::Size& final_size);
//
// Overrides
//
virtual ResizeTo* clone() const override;
void startWithTarget(cocos2d::Node* target) override;
void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
ResizeTo() {}
virtual ~ResizeTo() {}
/**
* initializes the action
* @param duration in seconds
* @param final_size in Size type
*/
bool initWithDuration(float duration, const cocos2d::Size& final_size);
protected:
cocos2d::Size _initialSize;
cocos2d::Size _finalSize;
cocos2d::Size _sizeDelta;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ResizeTo);
};
/** @class ResizeBy
* @brief Resize a Node object by a Size. Works on all nodes where setContentSize is effective. But it's mostly useful for nodes where 9-slice is enabled
*/
class CC_DLL ResizeBy : public ActionInterval
{
public:
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaSize The delta size.
* @return An autoreleased ResizeBy object.
*/
static ResizeBy* create(float duration, const cocos2d::Size& deltaSize);
//
// Overrides
//
virtual ResizeBy* clone() const override;
virtual ResizeBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time in seconds
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
ResizeBy() {}
virtual ~ResizeBy() {}
/** initializes the action */
bool initWithDuration(float duration, const cocos2d::Size& deltaSize);
protected:
cocos2d::Size _sizeDelta;
cocos2d::Size _startSize;
cocos2d::Size _previousSize;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ResizeBy);
};
/** @class JumpBy
* @brief Moves a Node object simulating a parabolic jump movement by modifying it's position attribute.
*/
class CC_DLL JumpBy : public ActionInterval
{
public:
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The jumping distance.
* @param height The jumping height.
* @param jumps The jumping times.
* @return An autoreleased JumpBy object.
*/
static JumpBy* create(float duration, const Vec2& position, float height, int jumps);
//
// Overrides
//
virtual JumpBy* clone() const override;
virtual JumpBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
JumpBy() {}
virtual ~JumpBy() {}
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
protected:
Vec2 _startPosition;
Vec2 _delta;
float _height;
int _jumps;
Vec2 _previousPos;
private:
CC_DISALLOW_COPY_AND_ASSIGN(JumpBy);
};
/** @class JumpTo
* @brief Moves a Node object to a parabolic position simulating a jump movement by modifying it's position attribute.
*/
class CC_DLL JumpTo : public JumpBy
{
public:
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The jumping destination position.
* @param height The jumping height.
* @param jumps The jumping times.
* @return An autoreleased JumpTo object.
*/
static JumpTo* create(float duration, const Vec2& position, float height, int jumps);
//
// Override
//
virtual void startWithTarget(Node *target) override;
virtual JumpTo* clone() const override;
virtual JumpTo* reverse() const override;
CC_CONSTRUCTOR_ACCESS:
JumpTo() {}
virtual ~JumpTo() {}
/**
* initializes the action
* @param duration In seconds.
*/
bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
protected:
Vec2 _endPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(JumpTo);
};
/** @struct Bezier configuration structure
*/
typedef struct _ccBezierConfig {
//! end position of the bezier
Vec2 endPosition;
//! Bezier control point 1
Vec2 controlPoint_1;
//! Bezier control point 2
Vec2 controlPoint_2;
} ccBezierConfig;
/** @class BezierBy
* @brief An action that moves the target with a cubic Bezier curve by a certain distance.
*/
class CC_DLL BezierBy : public ActionInterval
{
public:
/** Creates the action with a duration and a bezier configuration.
* @param t Duration time, in seconds.
* @param c Bezier config.
* @return An autoreleased BezierBy object.
* @code
* When this function bound to js or lua,the input params are changed.
* in js: var create(var t,var table)
* in lua: local create(local t, local table)
* @endcode
*/
static BezierBy* create(float t, const ccBezierConfig& c);
//
// Overrides
//
virtual BezierBy* clone() const override;
virtual BezierBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
BezierBy() {}
virtual ~BezierBy() {}
/**
* initializes the action with a duration and a bezier configuration
* @param t in seconds
*/
bool initWithDuration(float t, const ccBezierConfig& c);
protected:
ccBezierConfig _config;
Vec2 _startPosition;
Vec2 _previousPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(BezierBy);
};
/** @class BezierTo
* @brief An action that moves the target with a cubic Bezier curve to a destination point.
@since v0.8.2
*/
class CC_DLL BezierTo : public BezierBy
{
public:
/** Creates the action with a duration and a bezier configuration.
* @param t Duration time, in seconds.
* @param c Bezier config.
* @return An autoreleased BezierTo object.
* @code
* when this function bound to js or lua,the input params are changed
* in js: var create(var t,var table)
* in lua: local create(local t, local table)
* @endcode
*/
static BezierTo* create(float t, const ccBezierConfig& c);
//
// Overrides
//
virtual void startWithTarget(Node *target) override;
virtual BezierTo* clone() const override;
virtual BezierTo* reverse() const override;
CC_CONSTRUCTOR_ACCESS:
BezierTo() {}
virtual ~BezierTo() {}
/**
* @param t In seconds.
*/
bool initWithDuration(float t, const ccBezierConfig &c);
protected:
ccBezierConfig _toConfig;
private:
CC_DISALLOW_COPY_AND_ASSIGN(BezierTo);
};
/** @class ScaleTo
@brief Scales a Node object to a zoom factor by modifying it's scale attribute.
@warning This action doesn't support "reverse".
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleTo : public ActionInterval
{
public:
/**
* Creates the action with the same scale factor for X and Y.
* @param duration Duration time, in seconds.
* @param s Scale factor of x and y.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float s);
/**
* Creates the action with and X factor and a Y factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float sx, float sy);
/**
* Creates the action with X Y Z factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @param sz Scale factor of z.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float sx, float sy, float sz);
//
// Overrides
//
virtual ScaleTo* clone() const override;
virtual ScaleTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
ScaleTo() {}
virtual ~ScaleTo() {}
/**
* initializes the action with the same scale factor for X and Y
* @param duration in seconds
*/
bool initWithDuration(float duration, float s);
/**
* initializes the action with and X factor and a Y factor
* @param duration in seconds
*/
bool initWithDuration(float duration, float sx, float sy);
/**
* initializes the action with X Y Z factor
* @param duration in seconds
*/
bool initWithDuration(float duration, float sx, float sy, float sz);
protected:
float _scaleX;
float _scaleY;
float _scaleZ;
float _startScaleX;
float _startScaleY;
float _startScaleZ;
float _endScaleX;
float _endScaleY;
float _endScaleZ;
float _deltaX;
float _deltaY;
float _deltaZ;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ScaleTo);
};
/** @class ScaleBy
* @brief Scales a Node object a zoom factor by modifying it's scale attribute.
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleBy : public ScaleTo
{
public:
/**
* Creates the action with the same scale factor for X and Y.
* @param duration Duration time, in seconds.
* @param s Scale factor of x and y.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float s);
/**
* Creates the action with and X factor and a Y factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float sx, float sy);
/**
* Creates the action with X Y Z factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @param sz Scale factor of z.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float sx, float sy, float sz);
//
// Overrides
//
virtual void startWithTarget(Node *target) override;
virtual ScaleBy* clone() const override;
virtual ScaleBy* reverse() const override;
CC_CONSTRUCTOR_ACCESS:
ScaleBy() {}
virtual ~ScaleBy() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(ScaleBy);
};
/** @class Blink
* @brief Blinks a Node object by modifying it's visible attribute.
*/
class CC_DLL Blink : public ActionInterval
{
public:
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param blinks Blink times.
* @return An autoreleased Blink object.
*/
static Blink* create(float duration, int blinks);
//
// Overrides
//
virtual Blink* clone() const override;
virtual Blink* reverse() const override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
CC_CONSTRUCTOR_ACCESS:
Blink() {}
virtual ~Blink() {}
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, int blinks);
protected:
int _times;
bool _originalState;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Blink);
};
/** @class FadeTo
* @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
@warning This action doesn't support "reverse"
*/
class CC_DLL FadeTo : public ActionInterval
{
public:
/**
* Creates an action with duration and opacity.
* @param duration Duration time, in seconds.
* @param opacity A certain opacity, the range is from 0 to 255.
* @return An autoreleased FadeTo object.
*/
static FadeTo* create(float duration, uint8_t opacity);
//
// Overrides
//
virtual FadeTo* clone() const override;
virtual FadeTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
FadeTo() {}
virtual ~FadeTo() {}
/**
* initializes the action with duration and opacity
* @param duration in seconds
*/
bool initWithDuration(float duration, uint8_t opacity);
protected:
uint8_t _toOpacity;
uint8_t _fromOpacity;
friend class FadeOut;
friend class FadeIn;
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeTo);
};
/** @class FadeIn
* @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255.
The "reverse" of this action is FadeOut
*/
class CC_DLL FadeIn : public FadeTo
{
public:
/**
* Creates the action.
* @param d Duration time, in seconds.
* @return An autoreleased FadeIn object.
*/
static FadeIn* create(float d);
//
// Overrides
//
virtual void startWithTarget(Node *target) override;
virtual FadeIn* clone() const override;
virtual FadeTo* reverse() const override;
/**
* @js NA
*/
void setReverseAction(FadeTo* ac);
CC_CONSTRUCTOR_ACCESS:
FadeIn():_reverseAction(nullptr) {}
virtual ~FadeIn() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeIn);
FadeTo* _reverseAction;
};
/** @class FadeOut
* @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0.
The "reverse" of this action is FadeIn
*/
class CC_DLL FadeOut : public FadeTo
{
public:
/**
* Creates the action.
* @param d Duration time, in seconds.
*/
static FadeOut* create(float d);
//
// Overrides
//
virtual void startWithTarget(Node *target) override;
virtual FadeOut* clone() const override;
virtual FadeTo* reverse() const override;
/**
* @js NA
*/
void setReverseAction(FadeTo* ac);
CC_CONSTRUCTOR_ACCESS:
FadeOut():_reverseAction(nullptr) {}
virtual ~FadeOut() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeOut);
FadeTo* _reverseAction;
};
/** @class TintTo
* @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
@warning This action doesn't support "reverse"
@since v0.7.2
*/
class CC_DLL TintTo : public ActionInterval
{
public:
/**
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param red Red Color, from 0 to 255.
* @param green Green Color, from 0 to 255.
* @param blue Blue Color, from 0 to 255.
* @return An autoreleased TintTo object.
*/
static TintTo* create(float duration, uint8_t red, uint8_t green, uint8_t blue);
/**
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param color It's a Color3B type.
* @return An autoreleased TintTo object.
*/
static TintTo* create(float duration, const Color3B& color);
//
// Overrides
//
virtual TintTo* clone() const override;
virtual TintTo* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
TintTo() {}
virtual ~TintTo() {}
/** initializes the action with duration and color */
bool initWithDuration(float duration, uint8_t red, uint8_t green, uint8_t blue);
protected:
Color3B _to;
Color3B _from;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TintTo);
};
/** @class TintBy
@brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
@since v0.7.2
*/
class CC_DLL TintBy : public ActionInterval
{
public:
/**
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param deltaRed Delta red color.
* @param deltaGreen Delta green color.
* @param deltaBlue Delta blue color.
* @return An autoreleased TintBy object.
*/
static TintBy* create(float duration, int16_t deltaRed, int16_t deltaGreen, int16_t deltaBlue);
//
// Overrides
//
virtual TintBy* clone() const override;
virtual TintBy* reverse() const override;
virtual void startWithTarget(Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
TintBy() {}
virtual ~TintBy() {}
/** initializes the action with duration and color */
bool initWithDuration(float duration, int16_t deltaRed, int16_t deltaGreen, int16_t deltaBlue);
protected:
int16_t _deltaR;
int16_t _deltaG;
int16_t _deltaB;
int16_t _fromR;
int16_t _fromG;
int16_t _fromB;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TintBy);
};
/** @class DelayTime
* @brief Delays the action a certain amount of seconds.
*/
class CC_DLL DelayTime : public ActionInterval
{
public:
/**
* Creates the action.
* @param d Duration time, in seconds.
* @return An autoreleased DelayTime object.
*/
static DelayTime* create(float d);
//
// Overrides
//
/**
* @param time In seconds.
*/
virtual void update(float time) override;
virtual DelayTime* reverse() const override;
virtual DelayTime* clone() const override;
CC_CONSTRUCTOR_ACCESS:
DelayTime() {}
virtual ~DelayTime() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(DelayTime);
};
/** @class ReverseTime
* @brief Executes an action in reverse order, from time=duration to time=0
@warning Use this action carefully. This action is not
sequenceable. Use it as the default "reversed" method
of your own actions, but using it outside the "reversed"
scope is not recommended.
*/
class CC_DLL ReverseTime : public ActionInterval
{
public:
/** Creates the action.
*
* @param action a certain action.
* @return An autoreleased ReverseTime object.
*/
static ReverseTime* create(FiniteTimeAction *action);
//
// Overrides
//
virtual ReverseTime* reverse() const override;
virtual ReverseTime* clone() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
ReverseTime();
virtual ~ReverseTime();
/** initializes the action */
bool initWithAction(FiniteTimeAction *action);
protected:
FiniteTimeAction *_other;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ReverseTime);
};
class Texture2D;
/** @class Animate
* @brief Animates a sprite given the name of an Animation.
*/
class CC_DLL Animate : public ActionInterval
{
public:
/** Creates the action with an Animation and will restore the original frame when the animation is over.
*
* @param animation A certain animation.
* @return An autoreleased Animate object.
*/
static Animate* create(Animation *animation);
/** Sets the Animation object to be animated
*
* @param animation certain animation.
*/
void setAnimation( Animation* animation );
/** returns the Animation object that is being animated
*
* @return Gets the animation object that is being animated.
*/
Animation* getAnimation() { return _animation; }
const Animation* getAnimation() const { return _animation; }
/**
* Gets the index of sprite frame currently displayed.
* @return int the index of sprite frame currently displayed.
*/
int getCurrentFrameIndex() { return _currFrameIndex; }
//
// Overrides
//
virtual Animate* clone() const override;
virtual Animate* reverse() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
/**
* @param t In seconds.
*/
virtual void update(float t) override;
CC_CONSTRUCTOR_ACCESS:
Animate();
virtual ~Animate();
/** initializes the action with an Animation and will restore the original frame when the animation is over */
bool initWithAnimation(Animation *animation);
protected:
std::vector<float>* _splitTimes = new std::vector<float>;
int _nextFrame = 0;
SpriteFrame* _origFrame = nullptr;
int _currFrameIndex = 0;
unsigned int _executedLoops = 0;
Animation* _animation = nullptr;
EventCustom* _frameDisplayedEvent = nullptr;
AnimationFrame::DisplayedEventInfo _frameDisplayedEventInfo;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Animate);
};
/** @class TargetedAction
* @brief Overrides the target of an action so that it always runs on the target
* specified at action creation rather than the one specified by runAction.
*/
class CC_DLL TargetedAction : public ActionInterval
{
public:
/** Create an action with the specified action and forced target.
*
* @param target The target needs to override.
* @param action The action needs to override.
* @return An autoreleased TargetedAction object.
*/
static TargetedAction* create(Node* target, FiniteTimeAction* action);
/** Sets the target that the action will be forced to run with.
*
* @param forcedTarget The target that the action will be forced to run with.
*/
void setForcedTarget(Node* forcedTarget);
/** returns the target that the action is forced to run with.
*
* @return The target that the action is forced to run with.
*/
Node* getForcedTarget() { return _forcedTarget; }
const Node* getForcedTarget() const { return _forcedTarget; }
//
// Overrides
//
virtual TargetedAction* clone() const override;
virtual TargetedAction* reverse() const override;
virtual void startWithTarget(Node *target) override;
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
TargetedAction();
virtual ~TargetedAction();
/** Init an action with the specified action and forced target */
bool initWithTarget(Node* target, FiniteTimeAction* action);
protected:
FiniteTimeAction* _action;
Node* _forcedTarget;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TargetedAction);
};
/**
* @class ActionFloat
* @brief Action used to animate any value in range [from,to] over specified time interval
*/
class CC_DLL ActionFloat : public ActionInterval
{
public:
/**
* Callback function used to report back result
*/
typedef std::function<void(float value)> ActionFloatCallback;
/**
* Creates FloatAction with specified duration, from value, to value and callback to report back
* results
* @param duration of the action
* @param from value to start from
* @param to value to be at the end of the action
* @param callback to report back result
*
* @return An autoreleased ActionFloat object
*/
static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback);
/**
* Overridden ActionInterval methods
*/
void startWithTarget(Node* target) override;
void update(float delta) override;
ActionFloat* reverse() const override;
ActionFloat* clone() const override;
CC_CONSTRUCTOR_ACCESS:
ActionFloat() {};
virtual ~ActionFloat() {};
bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback);
protected:
/* From value */
float _from;
/* To value */
float _to;
/* delta time */
float _delta;
/* Callback to report back results */
ActionFloatCallback _callback;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ActionFloat);
};
// end of actions group
/// @}
NS_CC_END
#endif //__ACTION_CCINTERVAL_ACTION_H__