PuzzleSDK
ActionsTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2012 cocos2d-x.org
3 Copyright (c) 2013-2016 Chukong Technologies Inc.
4 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5
6 http://www.cocos2d-x.org
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 ****************************************************************************/
26
27#include "ActionsTest.h"
28#include "../testResource.h"
29#include "cocos2d.h"
30#include "ui/CocosGUI.h"
31
32#include "renderer/CCRenderer.h"
33#include "renderer/CCCustomCommand.h"
34#include "renderer/CCGroupCommand.h"
35
37using namespace cocos2d::ui;
38
39ActionsTests::ActionsTests()
40{
98}
99
100std::string ActionsDemo::title() const
101{
102 return "ActionsTest";
103}
104
106{
108
109 // Or you can create an sprite using a filename. only PNG is supported now.
110 _grossini = Sprite::create(s_pathGrossini);
111 _grossini->retain();
112
113 _tamara = Sprite::create(s_pathSister1);
114 _tamara->retain();
115
116 _kathia = Sprite::create(s_pathSister2);
117 _kathia->retain();
118
119 addChild(_grossini, 1);
120 addChild(_tamara, 2);
121 addChild(_kathia, 3);
122
124 _tamara->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2/3);
125 _kathia->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/2);
126}
127
129{
130 _grossini->release();
131 _tamara->release();
132 _kathia->release();
133
134 TestCase::onExit();
135}
136
137void ActionsDemo::centerSprites(unsigned int numberOfSprites)
138{
139 auto s = Director::getInstance()->getWinSize();
140
141 if( numberOfSprites == 0 )
142 {
143 _tamara->setVisible(false);
144 _kathia->setVisible(false);
145 _grossini->setVisible(false);
146 }
147 else if ( numberOfSprites == 1 )
148 {
149 _tamara->setVisible(false);
150 _kathia->setVisible(false);
151 _grossini->setPosition(s.width/2, s.height/2);
152 }
153 else if( numberOfSprites == 2 )
154 {
155 _kathia->setPosition(s.width/3, s.height/2);
156 _tamara->setPosition(2*s.width/3, s.height/2);
157 _grossini->setVisible(false);
158 }
159 else if( numberOfSprites == 3 )
160 {
161 _grossini->setPosition(s.width/2, s.height/2);
162 _tamara->setPosition(s.width/4, s.height/2);
163 _kathia->setPosition(3 * s.width/4, s.height/2);
164 }
165}
166
167void ActionsDemo::alignSpritesLeft(unsigned int numberOfSprites)
168{
169 auto s = Director::getInstance()->getWinSize();
170
171 if( numberOfSprites == 1 )
172 {
173 _tamara->setVisible(false);
174 _kathia->setVisible(false);
175 _grossini->setPosition(60, s.height/2);
176 }
177 else if( numberOfSprites == 2 )
178 {
179 _kathia->setPosition(60, s.height/3);
180 _tamara->setPosition(60, 2*s.height/3);
181 _grossini->setVisible( false );
182 }
183 else if( numberOfSprites == 3 )
184 {
185 _grossini->setPosition(60, s.height/2);
186 _tamara->setPosition(60, 2*s.height/3);
187 _kathia->setPosition(60, s.height/3);
188 }
189}
190
191//------------------------------------------------------------------
192//
193// ActionMove
194//
195//------------------------------------------------------------------
197{
199
200 centerSprites(3);
201
202 auto s = Director::getInstance()->getWinSize();
203
204 auto actionTo = MoveTo::create(2, Vec2(s.width-40, s.height-40));
205 auto actionBy = MoveBy::create(2, Vec2(80.0f,80.0f));
206 auto actionByBack = actionBy->reverse();
207
208 _tamara->runAction( actionTo);
209 _grossini->runAction( Sequence::create(actionBy, actionByBack, nullptr));
210 _kathia->runAction(MoveTo::create(1, Vec2(40.0f,40.0f)));
211}
212
213std::string ActionMove::subtitle() const
214{
215 return "MoveTo / MoveBy";
216}
217
218//------------------------------------------------------------------
219//
220// ActionMove3D
221//
222//------------------------------------------------------------------
224{
226
227 centerSprites(3);
228
229 auto s = Director::getInstance()->getWinSize();
230
231 _tamara->setPosition3D(Vec3(s.width-40, s.height-40, 0.0f));
232 _kathia->setPosition3D(Vec3(40.0f, 40.0f, 0.0f));
233
234 auto actionTo = MoveTo::create(2, Vec3(s.width-40, s.height-40, -100.0f));
235 auto actionBy = MoveBy::create(2, Vec3(80.0f, 80.0f, -100.0f));
236 auto actionByBack = actionBy->reverse();
237
238 _tamara->runAction(actionTo);
239 _grossini->runAction(Sequence::create(actionBy, actionByBack, nullptr));
240 _kathia->runAction(MoveTo::create(1, Vec3(40.0f, 40.0f, -100.0f)));
241}
242
243std::string ActionMove3D::subtitle() const
244{
245 return "MoveTo / MoveBy 3D";
246}
247
248//------------------------------------------------------------------
249//
250// ActionScale
251//
252//------------------------------------------------------------------
254{
256
257 centerSprites(3);
258
259 auto actionTo = ScaleTo::create(2.0f, 0.5f);
260 auto actionBy = ScaleBy::create(2.0f, 1.0f, 10.0f);
261 auto actionBy2 = ScaleBy::create(2.0f, 5.0f, 1.0f);
262
263 _grossini->runAction( actionTo);
264 _tamara->runAction( Sequence::create(actionBy, actionBy->reverse(), nullptr));
265 _kathia->runAction( Sequence::create(actionBy2, actionBy2->reverse(), nullptr));
266}
267
268std::string ActionScale::subtitle() const
269{
270 return "ScaleTo / ScaleBy";
271}
272
273//------------------------------------------------------------------
274//
275// ActionSkew
276//
277//------------------------------------------------------------------
279{
281
282 centerSprites(3);
283
284 auto actionTo = SkewTo::create(2, 37.2f, -37.2f);
285 auto actionToBack = SkewTo::create(2, 0, 0);
286 auto actionBy = SkewBy::create(2, 0.0f, -90.0f);
287 auto actionBy2 = SkewBy::create(2, 45.0f, 45.0f);
288 auto actionByBack = actionBy->reverse();
289
290 _tamara->runAction(Sequence::create(actionTo, actionToBack, nullptr));
291 _grossini->runAction(Sequence::create(actionBy, actionByBack, nullptr));
292
293 _kathia->runAction(Sequence::create(actionBy2, actionBy2->reverse(), nullptr));
294}
295
296std::string ActionSkew::subtitle() const
297{
298 return "SkewTo / SkewBy";
299}
300
301// ActionRotationalSkew
303{
305
306 this->centerSprites(3);
307
308 auto actionTo = RotateTo::create(2, 180, 180);
309 auto actionToBack = RotateTo::create(2, 0, 0);
310 auto actionBy = RotateBy::create(2, 0.0f, 360);
311 auto actionByBack = actionBy->reverse();
312
313 auto actionBy2 = RotateBy::create(2, 360, 0);
314 auto actionBy2Back = actionBy2->reverse();
315
316 _tamara->runAction( Sequence::create(actionBy, actionByBack, nullptr) );
317 _grossini->runAction( Sequence::create(actionTo, actionToBack, nullptr) );
318 _kathia->runAction( Sequence::create(actionBy2, actionBy2Back, nullptr) );
319}
320
322{
323 return "RotationalSkewTo / RotationalSkewBy";
324}
325
326
327
328//ActionRotationalSkewVSStandardSkew
330{
332
333 _tamara->removeFromParentAndCleanup(true);
334 _grossini->removeFromParentAndCleanup(true);
335 _kathia->removeFromParentAndCleanup(true);
336
337 auto s = Director::getInstance()->getWinSize();
338
339 Size boxSize(100.0f, 100.0f);
340
341 auto box = LayerColor::create(Color4B(255,255,0,255));
342 box->setAnchorPoint(Vec2(0.5f,0.5f));
343 box->setContentSize( boxSize );
344 box->setIgnoreAnchorPointForPosition(false);
345 box->setPosition(s.width/2, s.height - 100 - box->getContentSize().height/2);
346 this->addChild(box);
347
348 auto label = Label::createWithTTF("Standard cocos2d Skew", "fonts/Marker Felt.ttf", 16.0f);
349 label->setPosition(s.width/2, s.height - 100 + label->getContentSize().height);
350 this->addChild(label);
351
352 auto actionTo = SkewBy::create(2, 360, 0);
353 auto actionToBack = SkewBy::create(2, -360, 0);
354
355 box->runAction(Sequence::create(actionTo, actionToBack, nullptr));
356
357 box = LayerColor::create(Color4B(255,255,0,255));
358 box->setAnchorPoint(Vec2(0.5f,0.5f));
359 box->setContentSize(boxSize);
360 box->setIgnoreAnchorPointForPosition(false);
361 box->setPosition(s.width/2, s.height - 250 - box->getContentSize().height/2);
362 this->addChild(box);
363
364 label = Label::createWithTTF("Rotational Skew", "fonts/Marker Felt.ttf", 16.0f);
365 label->setPosition(s.width/2, s.height - 250 + label->getContentSize().height/2);
366 this->addChild(label);
367 auto actionTo2 = RotateBy::create(2, 360, 0);
368 auto actionToBack2 = RotateBy::create(2, -360, 0);
369 box->runAction(Sequence::create(actionTo2, actionToBack2, nullptr));
370}
372{
373 return "Skew Comparison";
374}
375
376// ActionSkewRotateScale
378{
380
381 _tamara->removeFromParentAndCleanup(true);
382 _grossini->removeFromParentAndCleanup(true);
383 _kathia->removeFromParentAndCleanup(true);
384
385 Size boxSize(100.0f, 100.0f);
386
387 auto box = LayerColor::create(Color4B(255, 255, 0, 255));
388 box->setAnchorPoint(Vec2(0.0f, 0.0f));
389 box->setPosition(190, 110);
390 box->setContentSize(boxSize);
391
392 static float markrside = 10.0f;
393 auto uL = LayerColor::create(Color4B(255, 0, 0, 255));
394 box->addChild(uL);
395 uL->setContentSize(Size(markrside, markrside));
396 uL->setPosition(0.f, boxSize.height - markrside);
397 uL->setAnchorPoint(Vec2(0.0f, 0.0f));
398
399 auto uR = LayerColor::create(Color4B(0, 0, 255, 255));
400 box->addChild(uR);
401 uR->setContentSize(Size(markrside, markrside));
402 uR->setPosition(boxSize.width - markrside, boxSize.height - markrside);
403 uR->setAnchorPoint(Vec2(0.0f, 0.0f));
404 addChild(box);
405
406 auto actionTo = SkewTo::create(2, 0.f, 2.f);
407 auto rotateTo = RotateTo::create(2, 61.0f);
408 auto actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
409
410 auto actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f);
411 auto rotateToBack = RotateTo::create(2, 0);
412 auto actionToBack = SkewTo::create(2, 0, 0);
413
414 box->runAction(Sequence::create(actionTo, actionToBack, nullptr));
415 box->runAction(Sequence::create(rotateTo, rotateToBack, nullptr));
416 box->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr));
417}
418
420{
421 return "Skew + Rotate + Scale";
422}
423
424//------------------------------------------------------------------
425//
426// ActionRotate
427//
428//------------------------------------------------------------------
430{
432
433 centerSprites(3);
434
435 auto actionTo = RotateTo::create( 2, 45);
436 auto actionTo2 = RotateTo::create( 2, -45);
437 auto actionTo0 = RotateTo::create(2 , 0);
438 _tamara->runAction( Sequence::create(actionTo, actionTo0, nullptr));
439
440 auto actionBy = RotateBy::create(2 , 360);
441 auto actionByBack = actionBy->reverse();
442 _grossini->runAction( Sequence::create(actionBy, actionByBack, nullptr));
443
444 _kathia->runAction( Sequence::create(actionTo2, actionTo0->clone(), nullptr));
445}
446
447std::string ActionRotate::subtitle() const
448{
449 return "RotateTo / RotateBy";
450}
451
452//------------------------------------------------------------------
453//
454// ActionRotateBy3D
455//
456//------------------------------------------------------------------
458{
460
461 centerSprites(3);
462
463 auto actionBy1 = RotateBy::create(4, Vec3(360.0f, 0.0f, 0.0f));
464 auto actionBy2 = RotateBy::create(4, Vec3(0.0f, 360.0f, 0.0f));
465 auto actionBy3 = RotateBy::create(4 ,Vec3(0.0f, 0.0f, 360.0f));
466
467 _tamara->runAction( Sequence::create(actionBy1, actionBy1->reverse(), nullptr));
468 _grossini->runAction( Sequence::create(actionBy2, actionBy2->reverse(), nullptr));
469 _kathia->runAction( Sequence::create(actionBy3, actionBy3->reverse(), nullptr));
470}
471
472std::string ActionRotateBy3D::subtitle() const
473{
474 return "RotateBy in 3D";
475}
476
477//------------------------------------------------------------------
478//
479// ActionJump
480//
481//------------------------------------------------------------------
483{
485
486 centerSprites(3);
487
488 auto actionTo = JumpTo::create(2, Vec2(300,300), 50, 4);
489 auto actionBy = JumpBy::create(2, Vec2(300,0), 50, 4);
490 auto actionUp = JumpBy::create(2, Vec2(0,0), 80, 4);
491 auto actionByBack = actionBy->reverse();
492
493 _tamara->runAction( actionTo);
494 _grossini->runAction( Sequence::create(actionBy, actionByBack, nullptr));
495 _kathia->runAction( RepeatForever::create(actionUp));
496}
497std::string ActionJump::subtitle() const
498{
499 return "JumpTo / JumpBy";
500}
501
502//------------------------------------------------------------------
503//
504// ActionBezier
505//
506//------------------------------------------------------------------
508{
510
511 auto s = Director::getInstance()->getWinSize();
512
513 //
514 // startPosition can be any coordinate, but since the movement
515 // is relative to the Bezier curve, make it (0,0)
516 //
517
518 centerSprites(3);
519
520 // sprite 1
521 ccBezierConfig bezier;
522 bezier.controlPoint_1 = Vec2(0.0f, s.height/2);
523 bezier.controlPoint_2 = Vec2(300.0f, -s.height/2);
524 bezier.endPosition = Vec2(300.0f,100.0f);
525
526 auto bezierForward = BezierBy::create(3, bezier);
527 auto bezierBack = bezierForward->reverse();
528 auto rep = RepeatForever::create(Sequence::create( bezierForward, bezierBack, nullptr));
529
530
531 // sprite 2
532 _tamara->setPosition(80,160);
533 ccBezierConfig bezier2;
534 bezier2.controlPoint_1 = Vec2(100.0f, s.height/2);
535 bezier2.controlPoint_2 = Vec2(200.0f, -s.height/2);
536 bezier2.endPosition = Vec2(240.0f,160.0f);
537
538 auto bezierTo1 = BezierTo::create(2, bezier2);
539
540 // sprite 3
541 _kathia->setPosition(400,160);
542 auto bezierTo2 = BezierTo::create(2, bezier2);
543
544 _grossini->runAction( rep);
545 _tamara->runAction(bezierTo1);
546 _kathia->runAction(bezierTo2);
547
548}
549
550std::string ActionBezier::subtitle() const
551{
552 return "BezierBy / BezierTo";
553}
554
555//------------------------------------------------------------------
556//
557// ActionBlink
558//
559//------------------------------------------------------------------
561{
563
564 centerSprites(2);
565
566 auto action1 = Blink::create(2, 10);
567 auto action2 = Blink::create(2, 5);
568
569 _tamara->runAction( action1);
570 _kathia->runAction(action2);
571}
572
573std::string ActionBlink::subtitle() const
574{
575 return "Blink";
576}
577
578//------------------------------------------------------------------
579//
580// ActionFade
581//
582//------------------------------------------------------------------
584{
586
587 centerSprites(2);
588
589 _tamara->setOpacity( 0 );
590 auto action1 = FadeIn::create(1.0f);
591 auto action1Back = action1->reverse();
592
593 auto action2 = FadeOut::create(1.0f);
594 auto action2Back = action2->reverse();
595 auto action2BackReverse = action2Back->reverse();
596 auto action2BackReverseReverse = action2BackReverse->reverse();
597
598 _tamara->setOpacity(122);
599 _tamara->runAction( Sequence::create( action1, action1Back, nullptr));
600 _kathia->setOpacity(122);
601 _kathia->runAction( Sequence::create( action2, action2Back,action2BackReverse,action2BackReverseReverse, nullptr));
602}
603
604std::string ActionFade::subtitle() const
605{
606 return "FadeIn / FadeOut";
607}
608
609//------------------------------------------------------------------
610//
611// ActionTint
612//
613//------------------------------------------------------------------
614
616{
618
619 centerSprites(2);
620
621 auto action1 = TintTo::create(2, 255, 0, 255);
622 auto action2 = TintBy::create(2, -127, -255, -127);
623 auto action2Back = action2->reverse();
624
625 _tamara->runAction( action1);
626 _kathia->runAction( Sequence::create( action2, action2Back, nullptr));
627}
628
629std::string ActionTint::subtitle() const
630{
631 return "TintTo / TintBy";
632}
633
634//------------------------------------------------------------------
635//
636// ActionAnimate
637//
638//------------------------------------------------------------------
640{
642
643 centerSprites(3);
644
645 //
646 // Manual animation
647 //
648 auto animation = Animation::create();
649 for( int i=1;i<15;i++)
650 {
651 char szName[100] = {0};
652 sprintf(szName, "Images/grossini_dance_%02d.png", i);
653 animation->addSpriteFrameWithFile(szName);
654 }
655 // should last 2.8 seconds. And there are 14 frames.
656 animation->setDelayPerUnit(2.8f / 14.0f);
657 animation->setRestoreOriginalFrame(true);
658
659 auto action = Animate::create(animation);
660 _grossini->runAction(Sequence::create(action, action->reverse(), nullptr));
661
662 //
663 // File animation
664 //
665 // With 2 loops and reverse
666 auto cache = AnimationCache::getInstance();
667 cache->addAnimationsWithFile("animations/animations-2.plist");
668 auto animation2 = cache->getAnimation("dance_1");
669
670 auto action2 = Animate::create(animation2);
671 _tamara->runAction(Sequence::create(action2, action2->reverse(), nullptr));
672
673 _frameDisplayedListener = EventListenerCustom::create(AnimationFrameDisplayedNotification, [](EventCustom * event){
674 auto userData = static_cast<AnimationFrame::DisplayedEventInfo*>(event->getUserData());
675
676 log("target %p with data %s", userData->target, Value(userData->userInfo).getDescription().c_str());
677 });
678
679 _eventDispatcher->addEventListenerWithFixedPriority(_frameDisplayedListener, -1);
680
681 //
682 // File animation
683 //
684 // with 4 loops
685 auto animation3 = animation2->clone();
686 animation3->setLoops(4);
687
688
689 auto action3 = Animate::create(animation3);
690 _kathia->runAction(action3);
691}
692
694{
696 _eventDispatcher->removeEventListener(_frameDisplayedListener);
697}
698
699std::string ActionAnimate::title() const
700{
701 return "Animation";
702}
703
704std::string ActionAnimate::subtitle() const
705{
706 return "Center: Manual animation. Border: using file format animation";
707}
708
709//------------------------------------------------------------------
710//
711// ActionSequence
712//
713//------------------------------------------------------------------
715{
717
719
720 auto action = Sequence::create(
721 MoveBy::create( 2, Vec2(240.0f,0.0f)),
722 RotateBy::create( 2, 540),
723 nullptr);
724
725 _grossini->runAction(action);
726}
727
728std::string ActionSequence::subtitle() const
729{
730 return "Sequence: Move + Rotate";
731}
732
733//------------------------------------------------------------------
734//
735// ActionSequence2
736//
737//------------------------------------------------------------------
739{
741
743
744 _grossini->setVisible(false);
745
746 auto action = Sequence::create(
747 Place::create(Vec2(200.0f,200.0f)),
748 Show::create(),
749 MoveBy::create(1, Vec2(100.0f,0.0f)),
750 CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback1,this)),
751 CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback2,this,_grossini)),
752 CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback3,this,_grossini,0xbebabeba)),
753 nullptr);
754
755 _grossini->runAction(action);
756}
757
759{
760 auto s = Director::getInstance()->getWinSize();
761 auto label = Label::createWithTTF("callback 1 called", "fonts/Marker Felt.ttf", 16.0f);
762 label->setPosition(s.width/4*1,s.height/2);
763
764 addChild(label);
765}
766
768{
769 auto s = Director::getInstance()->getWinSize();
770 auto label = Label::createWithTTF("callback 2 called", "fonts/Marker Felt.ttf", 16.0f);
771 label->setPosition(s.width/4*2,s.height/2);
772
773 addChild(label);
774}
775
776void ActionSequence2::callback3(Node* sender, long data)
777{
778 auto s = Director::getInstance()->getWinSize();
779 auto label = Label::createWithTTF("callback 3 called", "fonts/Marker Felt.ttf", 16.0f);
780 label->setPosition(s.width/4*3,s.height/2);
781
782 addChild(label);
783}
784
785std::string ActionSequence2::subtitle() const
786{
787 return "Sequence of InstantActions";
788}
789
790//------------------------------------------------------------------
791//
792// ActionSequence3
793//
794//------------------------------------------------------------------
796{
798
800
801 // Uses Array API
802 auto action1 = MoveBy::create(2, Vec2(240.0f,0.0f));
803 auto action2 = RotateBy::create(2, 540);
804 auto action3 = action1->reverse();
805 auto action4 = action2->reverse();
806
807 Vector<FiniteTimeAction*> array;
808 array.pushBack(action1);
809 array.pushBack(action2);
810 array.pushBack(action3);
811 array.pushBack(action4);
812 auto action = Sequence::create(array);
813 _grossini->runAction(action);
814}
815
816std::string ActionSequence3::subtitle() const
817{
818 return "Sequence: Using Array API";
819}
820
821//------------------------------------------------------------------
822//
823// ActionCallFuncN
824//
825//------------------------------------------------------------------
827{
829
830 centerSprites(1);
831
832 auto action = Sequence::create(
833 MoveBy::create(2.0f, Vec2(150.0f,0.0f)),
834 CallFuncN::create( CC_CALLBACK_1(ActionCallFuncN::callback, this)),
835 nullptr);
836
837 _grossini->runAction(action);
838}
839
840std::string ActionCallFuncN::title() const
841{
842 return "CallFuncN";
843}
844
845std::string ActionCallFuncN::subtitle() const
846{
847 return "Grossini should jump after moving";
848}
849
850void ActionCallFuncN::callback(Node* sender )
851{
852 auto a = JumpBy::create(5, Vec2(0,0), 100, 5);
853 sender->runAction(a);
854}
855//------------------------------------------------------------------
856//
857// ActionCallFuncND
858// CallFuncND is no longer needed. It can simulated with std::bind()
859//
860//------------------------------------------------------------------
862{
864
865 centerSprites(1);
866
867 auto action = Sequence::create(
868 MoveBy::create(2.0f, Vec2(200.0f,0.0f)),
869 CallFuncN::create( CC_CALLBACK_1(ActionCallFuncND::doRemoveFromParentAndCleanup, this, true)),
870 nullptr);
871
872 _grossini->runAction(action);
873}
874
875std::string ActionCallFuncND::title() const
876{
877 return "CallFuncND + auto remove";
878}
879
880std::string ActionCallFuncND::subtitle() const
881{
882 return "simulates CallFuncND with std::bind()";
883}
884
886{
887 _grossini->removeFromParentAndCleanup(cleanup);
888}
889
890//------------------------------------------------------------------
891//
892// ActionCallFunction
893//
894//------------------------------------------------------------------
896{
898
899 centerSprites(3);
900
901
902 auto action1 = Sequence::create(
903 MoveBy::create(2, Vec2(200.0f,0.0f)),
904 CallFunc::create( std::bind(&ActionCallFunction::callback1, this) ),
905 CallFunc::create(
906 // lambda
907 [&](){
908 auto s = Director::getInstance()->getWinSize();
909 auto label = Label::createWithTTF("called:lambda callback", "fonts/Marker Felt.ttf", 16.0f);
910 label->setPosition(s.width/4*1,s.height/2-40);
911 this->addChild(label);
912 } ),
913 nullptr);
914
915 auto action2 = Sequence::create(
916 ScaleBy::create(2 , 2),
917 FadeOut::create(2),
918 CallFunc::create( std::bind(&ActionCallFunction::callback2, this, _tamara) ),
919 nullptr);
920
921 auto action3 = Sequence::create(
922 RotateBy::create(3 , 360),
923 FadeOut::create(2),
924 CallFunc::create( std::bind(&ActionCallFunction::callback3, this, _kathia, 42) ),
925 nullptr);
926
927 _grossini->runAction(action1);
928 _tamara->runAction(action2);
929 _kathia->runAction(action3);
930}
931
932
934{
935 auto s = Director::getInstance()->getWinSize();
936 auto label = Label::createWithTTF("callback 1 called", "fonts/Marker Felt.ttf", 16.0f);
937 label->setPosition(s.width/4*1,s.height/2);
938
939 addChild(label);
940}
941
943{
944 auto s = Director::getInstance()->getWinSize();
945 auto label = Label::createWithTTF("callback 2 called", "fonts/Marker Felt.ttf", 16.0f);
946 label->setPosition(s.width/4*2,s.height/2);
947
948 addChild(label);
949
950 CCLOG("sender is: %p", sender);
951}
952
953void ActionCallFunction::callback3(Node* sender, long data)
954{
955 auto s = Director::getInstance()->getWinSize();
956 auto label = Label::createWithTTF("callback 3 called", "fonts/Marker Felt.ttf", 16.0f);
957 label->setPosition(s.width/4*3,s.height/2);
958 addChild(label);
959
960 CCLOG("target is: %p, data is: %ld", sender, data);
961}
962
964{
965 return "Callbacks: CallFunc with std::function()";
966}
967//------------------------------------------------------------------
968//
969// ActionSpawn
970//
971//------------------------------------------------------------------
972
974{
976
978
979 auto action = Spawn::create(
980 JumpBy::create(2, Vec2(300,0), 50, 4),
981 RotateBy::create( 2, 720),
982 nullptr);
983
984 _grossini->runAction(action);
985}
986
987std::string ActionSpawn::subtitle() const
988{
989 return "Spawn: Jump + Rotate";
990}
991
992//------------------------------------------------------------------
993//
994// ActionSpawn2
995//
996//------------------------------------------------------------------
997
999{
1001
1003
1004 auto action1 = JumpBy::create(2, Vec2(300,0), 50, 4);
1005 auto action2 = RotateBy::create( 2, 720);
1006
1007 Vector<FiniteTimeAction*> array;
1008 array.pushBack(action1);
1009 array.pushBack(action2);
1010
1011 auto action = Spawn::create(array);
1012 _grossini->runAction(action);
1013}
1014
1015std::string ActionSpawn2::subtitle() const
1016{
1017 return "Spawn: using the Array API";
1018}
1019
1020//------------------------------------------------------------------
1021//
1022// ActionRepeatForever
1023//
1024//------------------------------------------------------------------
1026{
1028
1029 centerSprites(1);
1030
1031 auto action = Sequence::create(
1032 DelayTime::create(1),
1033 CallFunc::create( std::bind( &ActionRepeatForever::repeatForever, this, _grossini) ),
1034 nullptr);
1035
1036 _grossini->runAction(action);
1037}
1038
1040{
1041 auto repeat = RepeatForever::create( RotateBy::create(1.0f, 360) );
1042
1043 sender->runAction(repeat);
1044}
1045
1047{
1048 return "CallFuncN + RepeatForever";
1049}
1050
1051
1052//------------------------------------------------------------------
1053//
1054// ActionRotateToRepeat
1055//
1056//------------------------------------------------------------------
1058{
1060
1061 centerSprites(2);
1062
1063 auto act1 = RotateTo::create(1, 90);
1064 auto act2 = RotateTo::create(1, 0);
1065 auto seq = Sequence::create(act1, act2, nullptr);
1066 auto rep1 = RepeatForever::create(seq);
1067 auto rep2 = Repeat::create( seq->clone(), 10);
1068
1069 _tamara->runAction(rep1);
1070 _kathia->runAction(rep2);
1071}
1072
1074{
1075 return "Repeat/RepeatForever + RotateTo";
1076}
1077
1078//------------------------------------------------------------------
1079//
1080// ActionReverse
1081//
1082//------------------------------------------------------------------
1084{
1086
1088
1089 auto jump = JumpBy::create(2, Vec2(300,0), 50, 4);
1090 auto action = Sequence::create( jump, jump->reverse(), nullptr);
1091
1092 _grossini->runAction(action);
1093}
1094
1095std::string ActionReverse::subtitle() const
1096{
1097 return "Reverse an action";
1098}
1099
1100
1101//------------------------------------------------------------------
1102//
1103// ActionDelayTime
1104//
1105//------------------------------------------------------------------
1107{
1109
1111
1112 auto move = MoveBy::create(1, Vec2(150.0f,0.0f));
1113 auto action = Sequence::create( move, DelayTime::create(2), move, nullptr);
1114
1115 _grossini->runAction(action);
1116}
1117
1118std::string ActionDelayTime::subtitle() const
1119{
1120 return "DelayTime: m + delay + m";
1121}
1122
1123
1124//------------------------------------------------------------------
1125//
1126// ActionReverseSequence
1127//
1128//------------------------------------------------------------------
1130{
1132
1134
1135 auto move1 = MoveBy::create(1, Vec2(250.0f,0.0f));
1136 auto move2 = MoveBy::create(1, Vec2(0.0f,50.0f));
1137 auto seq = Sequence::create( move1, move2, move1->reverse(), nullptr);
1138 auto action = Sequence::create( seq, seq->reverse(), nullptr);
1139
1140 _grossini->runAction(action);
1141}
1142
1144{
1145 return "Reverse a sequence";
1146}
1147
1148
1149//------------------------------------------------------------------
1150//
1151// ActionReverseSequence2
1152//
1153//------------------------------------------------------------------
1155{
1157
1159
1160
1161 // Test:
1162 // Sequence should work both with IntervalAction and InstantActions
1163 auto move1 = MoveBy::create(1, Vec2(250.0f,0.0f));
1164 auto move2 = MoveBy::create(1, Vec2(0.0f,50.0f));
1165 auto tog1 = ToggleVisibility::create();
1166 auto tog2 = ToggleVisibility::create();
1167 auto seq = Sequence::create( move1, tog1, move2, tog2, move1->reverse(), nullptr);
1168 auto action = Repeat::create(Sequence::create( seq, seq->reverse(), nullptr), 3);
1169
1170
1171 // Test:
1172 // Also test that the reverse of Hide is Show, and vice-versa
1173 _kathia->runAction(action);
1174
1175 auto move_tamara = MoveBy::create(1, Vec2(100.0f,0.0f));
1176 auto move_tamara2 = MoveBy::create(1, Vec2(50.0f,0.0f));
1177 auto hide = Hide::create();
1178 auto seq_tamara = Sequence::create( move_tamara, hide, move_tamara2, nullptr);
1179 auto seq_back = seq_tamara->reverse();
1180 _tamara->runAction( Sequence::create( seq_tamara, seq_back, nullptr));
1181}
1183{
1184 return "Reverse sequence 2";
1185}
1186
1187//------------------------------------------------------------------
1188//
1189// ActionRepeat
1190//
1191//------------------------------------------------------------------
1193{
1195
1197
1198
1199 auto a1 = MoveBy::create(1, Vec2(150.0f,0.0f));
1200 auto action1 = Repeat::create(
1201 Sequence::create( Place::create(Vec2(60.0f,60.0f)), a1, nullptr) ,
1202 3);
1203 auto action2 = RepeatForever::create(
1204 Sequence::create(a1->clone(), a1->reverse(), nullptr)
1205 );
1206
1207 _kathia->runAction(action1);
1208 _tamara->runAction(action2);
1209}
1210
1211std::string ActionRepeat::subtitle() const
1212{
1213 return "Repeat / RepeatForever actions";
1214}
1215
1216//------------------------------------------------------------------
1217//
1218// ActionOrbit
1219//
1220//------------------------------------------------------------------
1222{
1224
1225 Director::getInstance()->setProjection(Director::Projection::_2D);
1226 centerSprites(3);
1227
1228 auto orbit1 = OrbitCamera::create(2,1, 0, 0, 180, 0, 0);
1229 auto action1 = Sequence::create(
1230 orbit1,
1231 orbit1->reverse(),
1232 nullptr);
1233
1234 auto orbit2 = OrbitCamera::create(2,1, 0, 0, 180, -45, 0);
1235 auto action2 = Sequence::create(
1236 orbit2,
1237 orbit2->reverse(),
1238 nullptr);
1239
1240 auto orbit3 = OrbitCamera::create(2,1, 0, 0, 180, 90, 0);
1241 auto action3 = Sequence::create(
1242 orbit3,
1243 orbit3->reverse(),
1244 nullptr);
1245
1246 _kathia->runAction(RepeatForever::create(action1));
1247 _tamara->runAction(RepeatForever::create(action2));
1248 _grossini->runAction(RepeatForever::create(action3));
1249
1250 auto move = MoveBy::create(3, Vec2(100.0f,-100.0f));
1251 auto move_back = move->reverse();
1252 auto seq = Sequence::create(move, move_back, nullptr);
1253 auto rfe = RepeatForever::create(seq);
1254 _kathia->runAction(rfe);
1255 _tamara->runAction(rfe->clone() );
1256 _grossini->runAction( rfe->clone() );
1257}
1258
1260{
1262
1263 Director::getInstance()->setProjection(Director::Projection::DEFAULT);
1264}
1265
1266std::string ActionOrbit::subtitle() const
1267{
1268 return "OrbitCamera action";
1269}
1270
1271//------------------------------------------------------------------
1272//
1273// ActionFollow
1274//
1275//------------------------------------------------------------------
1277{
1279
1280 centerSprites(1);
1281 auto s = Director::getInstance()->getWinSize();
1282
1283 DrawNode* drawNode = DrawNode::create();
1284 float x = s.width*2 - 100;
1285 float y = s.height;
1286
1287 Vec2 vertices[] = { Vec2(5.0f,5.0f), Vec2(x-5,5.0f), Vec2(x-5,y-5), Vec2(5.0f,y-5) };
1288 drawNode->drawPoly(vertices, 4, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
1289
1290 this->addChild(drawNode);
1291
1292 _grossini->setPosition(-200.0f, s.height / 2);
1293 auto move = MoveBy::create(2, Vec2(s.width * 3, 0.0f));
1294 auto move_back = move->reverse();
1295 auto seq = Sequence::create(move, move_back, nullptr);
1296 auto rep = RepeatForever::create(seq);
1297
1298 _grossini->runAction(rep);
1299
1300 this->runAction(Follow::create(_grossini, Rect(0.0f, 0.0f, s.width * 2 - 100, s.height)));
1301}
1302
1303std::string ActionFollow::subtitle() const
1304{
1305 return "Follow action";
1306}
1307
1308//------------------------------------------------------------------
1309//
1310// ActionFollowWithOffset
1311//
1312//------------------------------------------------------------------
1314{
1316
1317 centerSprites(1);
1318 auto s = Director::getInstance()->getWinSize();
1319
1320 DrawNode* drawNode = DrawNode::create();
1321 float x = s.width*2 - 100;
1322 float y = s.height;
1323
1324 Vec2 vertices[] = { Vec2(5.0f,5.0f), Vec2(x-5,5.0f), Vec2(x-5,y-5), Vec2(5.0f,y-5) };
1325 drawNode->drawPoly(vertices, 4, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
1326
1327 this->addChild(drawNode);
1328
1329 _grossini->setPosition(-200, s.height / 2);
1330 auto move = MoveBy::create(2, Vec2(s.width * 3, 1.0f));
1331 auto move_back = move->reverse();
1332 auto seq = Sequence::create(move, move_back, nullptr);
1333 auto rep = RepeatForever::create(seq);
1334
1335 _grossini->runAction(rep);
1336
1337 //sample offset values set
1338 float verticalOffset = -900;
1339 float horizontalOffset = 200;
1340 this->runAction(Follow::createWithOffset(_grossini, horizontalOffset,verticalOffset,Rect(0.0f, 0.0f, s.width * 2 - 100, s.height)));
1341}
1342
1344{
1345 return "Follow action with horizontal and vertical offset";
1346}
1347
1348
1350{
1352 centerSprites(2);
1353
1354
1355 auto jump1 = JumpBy::create(2,Vec2::ZERO,100,3);
1356 auto jump2 = jump1->clone();
1357 auto rot1 = RotateBy::create(1, 360);
1358 auto rot2 = rot1->clone();
1359
1360 auto t1 = TargetedAction::create(_kathia, jump2);
1361 auto t2 = TargetedAction::create(_kathia, rot2);
1362
1363 auto seq = Sequence::create(jump1, t1, rot1, t2, nullptr);
1364 auto always = RepeatForever::create(seq);
1365
1366 _tamara->runAction(always);
1367}
1368
1369std::string ActionTargeted::title() const
1370{
1371 return "ActionTargeted";
1372}
1373
1374std::string ActionTargeted::subtitle() const
1375{
1376 return "Action that runs on another target. Useful for sequences";
1377}
1378
1379
1381{
1383 centerSprites(2);
1384
1385
1386 auto jump1 = JumpBy::create(2,Vec2::ZERO,100,3);
1387 auto jump2 = jump1->clone();
1388 auto rot1 = RotateBy::create(1, 360);
1389 auto rot2 = rot1->clone();
1390
1391 auto t1 = TargetedAction::create(_kathia, jump2);
1392 auto t2 = TargetedAction::create(_kathia, rot2);
1393
1394 auto seq = Sequence::create(jump1, t1->reverse(), rot1, t2->reverse(), nullptr);
1395 auto always = RepeatForever::create(seq);
1396
1397 _tamara->runAction(always);
1398}
1399
1401{
1402 return "ActionTargetedReverse";
1403}
1404
1406{
1407 return "Action that runs reversely on another target. Useful for sequences";
1408}
1409
1410// ActionStacked
1411
1413{
1415
1416 this->centerSprites(0);
1417
1418 auto listener = EventListenerTouchAllAtOnce::create();
1419 listener->onTouchesEnded = CC_CALLBACK_2(ActionStacked::onTouchesEnded, this);
1420 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
1421
1422 auto s = Director::getInstance()->getWinSize();
1423 this->addNewSpriteWithCoords(Vec2(s.width/2, s.height/2));
1424}
1425
1427{
1428 int idx = static_cast<int>(CCRANDOM_0_1() * 1400 / 100);
1429 float w = 85.0f;
1430 float h = 121.0f;
1431 float x = (idx%5) * w;
1432 float y = (idx/5) * h;
1433
1434 auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(x,y,w,h));
1435
1436 sprite->setPosition(p);
1437 this->addChild(sprite);
1438
1439 this->runActionsInSprite(sprite);
1440}
1441
1443{
1444 // override me
1445}
1446
1447void ActionStacked::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
1448{
1449 for ( auto &touch: touches ) {
1450 auto location = touch->getLocation();
1451 addNewSpriteWithCoords( location );
1452 }
1453}
1454
1455std::string ActionStacked::title() const
1456{
1457 return "Override me";
1458}
1459
1460std::string ActionStacked::subtitle() const
1461{
1462 return "Tap screen";
1463}
1464
1465// ActionMoveStacked
1466
1467
1469{
1470 sprite->runAction(
1471 RepeatForever::create(
1472 Sequence::create(
1473 MoveBy::create(0.05f, Vec2(10.0f,10.0f)),
1474 MoveBy::create(0.05f, Vec2(-10.0f,-10.0f)),
1475 nullptr)));
1476
1477 auto action = MoveBy::create(2.0f, Vec2(400.0f,0.0f));
1478 auto action_back = action->reverse();
1479
1480 sprite->runAction(
1481 RepeatForever::create(
1482 Sequence::create(action, action_back, nullptr)
1483 ));
1484}
1485
1486
1487std::string ActionMoveStacked::title() const
1488{
1489 return "Stacked MoveBy/To actions";
1490}
1491
1492// ActionMoveJumpStacked
1493
1495{
1496 sprite->runAction(
1497 RepeatForever::create(
1498 Sequence::create(
1499 MoveBy::create(0.05f, Vec2(10,2)),
1500 MoveBy::create(0.05f, Vec2(-10,-2)),
1501 nullptr)));
1502
1503 auto jump = JumpBy::create(2.0f, Vec2(400,0), 100, 5);
1504 auto jump_back = jump->reverse();
1505
1506 sprite->runAction(
1507 RepeatForever::create(
1508 Sequence::create(jump, jump_back, nullptr)
1509 ));
1510}
1511
1513{
1514 return "tacked Move + Jump actions";
1515}
1516
1517// ActionMoveBezierStacked
1518
1520{
1521 auto s = Director::getInstance()->getWinSize();
1522
1523 // sprite 1
1524 ccBezierConfig bezier;
1525 bezier.controlPoint_1 = Vec2(0.0f, s.height/2);
1526 bezier.controlPoint_2 = Vec2(300.0f, -s.height/2);
1527 bezier.endPosition = Vec2(300.0f,100.0f);
1528
1529 auto bezierForward = BezierBy::create(3, bezier);
1530 auto bezierBack = bezierForward->reverse();
1531 auto seq = Sequence::create(bezierForward, bezierBack, nullptr);
1532 auto rep = RepeatForever::create(seq);
1533 sprite->runAction(rep);
1534
1535 sprite->runAction(
1536 RepeatForever::create(
1537 Sequence::create(
1538 MoveBy::create(0.05f, Vec2(10.0f,0.0f)),
1539 MoveBy::create(0.05f, Vec2(-10.0f,0.0f)),
1540 nullptr)));
1541}
1542
1544{
1545 return "Stacked Move + Bezier actions";
1546}
1547
1548
1549// ActionCatmullRomStacked
1550
1552{
1554
1555 this->centerSprites(2);
1556
1557 auto s = Director::getInstance()->getWinSize();
1558
1559 //
1560 // sprite 1 (By)
1561 //
1562 // startPosition can be any coordinate, but since the movement
1563 // is relative to the Catmull Rom curve, it is better to start with (0,0).
1564 //
1565
1566 _tamara->setPosition(50,50);
1567
1568 auto array = PointArray::create(20);
1569
1570 array->addControlPoint(Vec2(0.0f,0.0f));
1571 array->addControlPoint(Vec2(80.0f,80.0f));
1572 array->addControlPoint(Vec2(s.width-80,80.0f));
1573 array->addControlPoint(Vec2(s.width-80,s.height-80.0f));
1574 array->addControlPoint(Vec2(80.0f,s.height-80.0f));
1575 array->addControlPoint(Vec2(80.0f,80.0f));
1576 array->addControlPoint(Vec2(s.width/2, s.height/2));
1577
1578 auto action = CatmullRomBy::create(3, array);
1579 auto reverse = action->reverse();
1580
1581 auto seq = Sequence::create(action, reverse, nullptr);
1582
1583 _tamara->runAction(seq);
1584
1585 _tamara->runAction(
1586 RepeatForever::create(
1587 Sequence::create(
1588 MoveBy::create(0.05f, Vec2(10.0f,0.0f)),
1589 MoveBy::create(0.05f, Vec2(-10.0f,0.0f)),
1590 nullptr)));
1591
1592 auto drawNode1 = DrawNode::create();
1593 drawNode1->setPosition(Vec2(50.0f,50.0f));
1594 drawNode1->drawCatmullRom(array, 50, Color4F(1.0f, 1.0f, 0.0f, 0.5f));
1595 this->addChild(drawNode1);
1596
1597 //
1598 // sprite 2 (To)
1599 //
1600 // The startPosition is not important here, because it uses a "To" action.
1601 // The initial position will be the 1st point of the Catmull Rom path
1602 //
1603
1604 auto array2 = PointArray::create(20);
1605
1606 array2->addControlPoint(Vec2(s.width/2, 30.0f));
1607 array2->addControlPoint(Vec2(s.width-80,30.0f));
1608 array2->addControlPoint(Vec2(s.width-80.0f,s.height-80.0f));
1609 array2->addControlPoint(Vec2(s.width/2,s.height-80.0f));
1610 array2->addControlPoint(Vec2(s.width/2, 30.0f));
1611
1612 auto action2 = CatmullRomTo::create(3, array2);
1613 auto reverse2 = action2->reverse();
1614
1615 auto seq2 = Sequence::create(action2, reverse2, nullptr);
1616
1617 _kathia->runAction(seq2);
1618
1619 _kathia->runAction(
1620 RepeatForever::create(
1621 Sequence::create(
1622 MoveBy::create(0.05f, Vec2(10.0f,0.0f)),
1623 MoveBy::create(0.05f, Vec2(-10.0f,0.0f)),
1624 nullptr)));
1625
1626 auto drawNode2 = DrawNode::create();
1627 drawNode2->drawCatmullRom(array2, 50, Color4F(1.0, 0.0, 0.0, 0.5));
1628 this->addChild(drawNode2);
1629}
1630
1632{
1633}
1634
1636{
1637 return "Stacked MoveBy + CatmullRom actions";
1638}
1639
1641{
1642 return "MoveBy + CatmullRom at the same time in the same sprite";
1643}
1644
1645
1646// ActionCardinalSplineStacked
1647
1649{
1651
1652 this->centerSprites(2);
1653
1654 auto s = Director::getInstance()->getWinSize();
1655
1656 auto array = PointArray::create(20);
1657
1658 array->addControlPoint(Vec2(0.0f, 0.0f));
1659 array->addControlPoint(Vec2(s.width/2-30,0.0f));
1660 array->addControlPoint(Vec2(s.width/2-30,s.height-80.0f));
1661 array->addControlPoint(Vec2(0.0f, s.height-80.0f));
1662 array->addControlPoint(Vec2(0.0f, 0.0f));
1663
1664
1665 //
1666 // sprite 1 (By)
1667 //
1668 // Spline with no tension (tension==0)
1669 //
1670
1671 auto action = CardinalSplineBy::create(3, array, 0);
1672 auto reverse = action->reverse();
1673
1674 auto seq = Sequence::create(action, reverse, nullptr);
1675
1676 _tamara->setPosition(50,50);
1677 _tamara->runAction(seq);
1678
1679 _tamara->runAction(
1680 RepeatForever::create(
1681 Sequence::create(
1682 MoveBy::create(0.05f, Vec2(10.0f,0.0f)),
1683 MoveBy::create(0.05f, Vec2(-10.0f,0.0f)),
1684 nullptr)));
1685
1686 auto drawNode1 = DrawNode::create();
1687 drawNode1->setPosition(Vec2(50.0f,50.0f));
1688 drawNode1->drawCardinalSpline(array, 0, 100, Color4F(1.0f, 0.0f, 1.0f, 1.0f));
1689 this->addChild(drawNode1);
1690
1691 //
1692 // sprite 2 (By)
1693 //
1694 // Spline with high tension (tension==1)
1695 //
1696
1697 auto *action2 = CardinalSplineBy::create(3, array, 1);
1698 auto reverse2 = action2->reverse();
1699
1700 auto seq2 = Sequence::create(action2, reverse2, nullptr);
1701
1702 _kathia->setPosition(s.width/2,50);
1703
1704 _kathia->runAction(seq2);
1705
1706 _kathia->runAction(
1707 RepeatForever::create(
1708 Sequence::create(
1709 MoveBy::create(0.05f, Vec2(10.0f,0.0f)),
1710 MoveBy::create(0.05f, Vec2(-10.0f,0.0f)),
1711 nullptr)));
1712
1713 auto drawNode2 = DrawNode::create();
1714 drawNode2->setPosition(Vec2(s.width/2,50.0f));
1715 drawNode2->drawCardinalSpline(array, 1, 100, Color4F(0.0f, 0.0f, 1.0f, 1.0f));
1716 this->addChild(drawNode2);
1717}
1718
1720{
1721}
1722
1724{
1725 return "Stacked MoveBy + CardinalSpline actions";
1726}
1727
1729{
1730 return "CCMoveBy + CardinalSplineBy/To at the same time";
1731}
1732
1733// Issue1305
1735{
1737 centerSprites(0);
1738
1739 _spriteTmp = Sprite::create("Images/grossini.png");
1740 _spriteTmp->runAction(CallFunc::create(std::bind(&Issue1305::log, this, _spriteTmp)));
1741 _spriteTmp->retain();
1742
1743 scheduleOnce([&](float dt) {
1744 _spriteTmp->setPosition(250,250);
1745 addChild(_spriteTmp);
1746 },2 ,"update_key");
1747
1748}
1749
1750void Issue1305::log(Node* sender)
1751{
1752 cocos2d::log("This message SHALL ONLY appear when the sprite is added to the scene, NOT BEFORE");
1753}
1754
1756{
1757 _spriteTmp->stopAllActions();
1758 _spriteTmp->release();
1760}
1761
1762std::string Issue1305::title() const
1763{
1764 return "Issue 1305";
1765}
1766
1767std::string Issue1305::subtitle() const
1768{
1769 return "In two seconds you should see a message on the console. NOT BEFORE.";
1770}
1771
1773{
1775 centerSprites(0);
1776
1777 auto spr = Sprite::create("Images/grossini.png");
1778 spr->setPosition(200,200);
1779 addChild(spr);
1780
1781 auto act1 = MoveBy::create(2 ,Vec2(0.0f, 100.0f));
1782 /* c++ can't support block, so we use CallFuncN instead.
1783 id act2 = [CallBlock actionWithBlock:^{
1784 NSLog(@"1st block");
1785 });
1786 id act3 = [MoveBy create:2, Vec2(0, -100));
1787 id act4 = [CallBlock actionWithBlock:^{
1788 NSLog(@"2nd block");
1789 });
1790 id act5 = [MoveBy create:2, Vec2(100, -100));
1791 id act6 = [CallBlock actionWithBlock:^{
1792 NSLog(@"3rd block");
1793 });
1794 id act7 = [MoveBy create:2, Vec2(-100, 0));
1795 id act8 = [CallBlock actionWithBlock:^{
1796 NSLog(@"4th block");
1797 });
1798 */
1799
1800 auto act2 = CallFunc::create( std::bind( &Issue1305_2::printLog1, this));
1801 auto act3 = MoveBy::create(2, Vec2(0.0f, -100.0f));
1802 auto act4 = CallFunc::create( std::bind( &Issue1305_2::printLog2, this));
1803 auto act5 = MoveBy::create(2, Vec2(100.0f, -100.0f));
1804 auto act6 = CallFunc::create( std::bind( &Issue1305_2::printLog3, this));
1805 auto act7 = MoveBy::create(2, Vec2(-100.0f, 0.0f));
1806 auto act8 = CallFunc::create( std::bind( &Issue1305_2::printLog4, this));
1807
1808 auto actF = Sequence::create(act1, act2, act3, act4, act5, act6, act7, act8, nullptr);
1809
1810 // [spr runAction:actF);
1811 Director::getInstance()->getActionManager()->addAction(actF ,spr, false);
1812
1813}
1814
1816{
1817 log("1st block");
1818}
1819
1821{
1822 log("2nd block");
1823}
1824
1826{
1827 log("3rd block");
1828}
1829
1831{
1832 log("4th block");
1833}
1834
1835std::string Issue1305_2::title() const
1836{
1837 return "Issue 1305 #2";
1838}
1839
1840std::string Issue1305_2::subtitle() const
1841{
1842 return "See console. You should only see one message for each block";
1843}
1844
1846{
1848 centerSprites(0);
1849
1850 auto spr = Sprite::create("Images/grossini.png");
1851 spr->setPosition(100, 100);
1852 addChild(spr);
1853
1854 auto act1 = MoveBy::create(0.5, Vec2(100.0f, 0.0f));
1855 auto act2 = act1->reverse();
1856 auto act3 = Sequence::create(act1, act2, nullptr);
1857 auto act4 = Repeat::create(act3, 2);
1858
1859 spr->runAction(act4);
1860}
1861
1862std::string Issue1288::title() const
1863{
1864 return "Issue 1288";
1865}
1866
1867std::string Issue1288::subtitle() const
1868{
1869 return "Sprite should end at the position where it started.";
1870}
1871
1873{
1875 centerSprites(0);
1876
1877 auto spr = Sprite::create("Images/grossini.png");
1878 spr->setPosition(100, 100);
1879 addChild(spr);
1880
1881 auto act1 = MoveBy::create(0.5, Vec2(100.0f, 0.0f));
1882 spr->runAction(Repeat::create(act1, 1));
1883}
1884
1885std::string Issue1288_2::title() const
1886{
1887 return "Issue 1288 #2";
1888}
1889
1890std::string Issue1288_2::subtitle() const
1891{
1892 return "Sprite should move 100 pixels, and stay there";
1893}
1894
1895
1897{
1899 centerSprites(0);
1900
1901 auto spr = Sprite::create("Images/grossini.png");
1902 spr->setPosition(100, 100);
1903 addChild(spr);
1904
1905 auto act1 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
1906 auto act2 = RotateBy::create(0.25, 45);
1907 auto act3 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
1908 auto act4 = RotateBy::create(0.25, 45);
1909 auto act5 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
1910 auto act6 = RotateBy::create(0.25, 45);
1911 auto act7 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
1912 auto act8 = RotateBy::create(0.25, 45);
1913 auto act9 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
1914
1915 auto actF = Sequence::create(act1, act2, act3, act4, act5, act6, act7, act8, act9, nullptr);
1916 spr->runAction(actF);
1917}
1918
1919std::string Issue1327::title() const
1920{
1921 return "Issue 1327";
1922}
1923
1924std::string Issue1327::subtitle() const
1925{
1926 return "See console: You should see: 0, 45, 90, 135, 180";
1927}
1928
1929void Issue1327::logSprRotation(Sprite* sender)
1930{
1931 log("%f", sender->getRotation());
1932}
1933
1934//Issue1398
1936{
1937 _testInteger++;
1938 log("incremented to %d", _testInteger);
1939}
1940
1942{
1944 this->centerSprites(0);
1945
1946 _testInteger = 0;
1947 log("testInt = %d", _testInteger);
1948
1949 this->runAction(
1950 Sequence::create(
1951 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"1")),
1952 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"2")),
1953 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"3")),
1954 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"4")),
1955 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"5")),
1956 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"6")),
1957 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"7")),
1958 CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"8")),
1959 nullptr));
1960}
1961
1963{
1964 this->incrementInteger();
1965 log("%s", (char*)data);
1966}
1967
1968std::string Issue1398::subtitle() const
1969{
1970 return "See console: You should see an 8";
1971}
1972
1973std::string Issue1398::title() const
1974{
1975 return "Issue 1398";
1976}
1977
1979{
1981 this->centerSprites(0);
1982
1983 _count = 0;
1984 log("before: count = %d", _count);
1985
1986 log("start count up 50 times using Repeat action");
1987 auto delay = 1.0f / 50;
1988 auto repeatAction = Repeat::create(
1989 Sequence::createWithTwoActions(
1990 CallFunc::create([&](){ this->_count++; }),
1991 DelayTime::create(delay)),
1992 50);
1993 this->runAction(
1994 Sequence::createWithTwoActions(
1995 repeatAction,
1996 CallFunc::create([&]() { log("after: count = %d", this->_count); })
1997 ));
1998}
1999
2000std::string Issue2599::subtitle() const
2001{
2002 return "See console: You should see '50'";
2003}
2004
2005std::string Issue2599::title() const
2006{
2007 return "Issue 2599";
2008}
2009
2013{
2015
2016 this->centerSprites(2);
2017
2018 auto s = Director::getInstance()->getWinSize();
2019
2020 //
2021 // sprite 1 (By)
2022 //
2023 // startPosition can be any coordinate, but since the movement
2024 // is relative to the Catmull Rom curve, it is better to start with (0,0).
2025 //
2026
2027 _tamara->setPosition(50, 50);
2028
2029 auto array = PointArray::create(20);
2030
2031 array->addControlPoint(Vec2(0.0f, 0.0f));
2032 array->addControlPoint(Vec2(80.0f, 80.0f));
2033 array->addControlPoint(Vec2(s.width - 80, 80.0f));
2034 array->addControlPoint(Vec2(s.width - 80, s.height - 80));
2035 array->addControlPoint(Vec2(80.0f, s.height - 80.0f));
2036 array->addControlPoint(Vec2(80.0f, 80.0f));
2037 array->addControlPoint(Vec2(s.width / 2, s.height / 2));
2038
2039 auto action = CatmullRomBy::create(3, array);
2040 auto reverse = action->reverse();
2041
2042 auto seq = Sequence::create(action, reverse, nullptr);
2043
2044 _tamara->runAction(seq);
2045
2046 auto drawNode1 = DrawNode::create();
2047 drawNode1->setPosition(Vec2(50.0f,50.0f));
2048 drawNode1->drawCatmullRom(array, 50, Color4F(1.0f, 0.0f, 1.0f, 1.0f));
2049 this->addChild(drawNode1);
2050
2051 //
2052 // sprite 2 (To)
2053 //
2054 // The startPosition is not important here, because it uses a "To" action.
2055 // The initial position will be the 1st point of the Catmull Rom path
2056 //
2057
2058 auto array2 = PointArray::create(20);
2059
2060 array2->addControlPoint(Vec2(s.width / 2, 30.0f));
2061 array2->addControlPoint(Vec2(s.width -80, 30.0f));
2062 array2->addControlPoint(Vec2(s.width - 80, s.height - 80));
2063 array2->addControlPoint(Vec2(s.width / 2, s.height - 80));
2064 array2->addControlPoint(Vec2(s.width / 2, 30.0f));
2065
2066 auto action2 = CatmullRomTo::create(3, array2);
2067 auto reverse2 = action2->reverse();
2068
2069 auto seq2 = Sequence::create(action2, reverse2, nullptr);
2070
2071 _kathia->runAction(seq2);
2072
2073 auto drawNode2 = DrawNode::create();
2074 drawNode2->drawCatmullRom(array2, 50, Color4F(0.0f, 1.0f, 1.0f, 1.0f));
2075 this->addChild(drawNode2);
2076}
2077
2079{
2080}
2081
2082std::string ActionCatmullRom::title() const
2083{
2084 return "CatmullRomBy / CatmullRomTo";
2085}
2086
2088{
2089 return "Catmull Rom spline paths. Testing reverse too";
2090}
2091
2095{
2097
2098 this->centerSprites(2);
2099
2100 auto s = Director::getInstance()->getWinSize();
2101
2102 auto array = PointArray::create(20);
2103
2104 array->addControlPoint(Vec2(0.0f, 0.0f));
2105 array->addControlPoint(Vec2(s.width/2-30, 0.0f));
2106 array->addControlPoint(Vec2(s.width/2-30, s.height-80));
2107 array->addControlPoint(Vec2(0.0f, s.height-80));
2108 array->addControlPoint(Vec2(0.0f, 0.0f));
2109
2110 //
2111 // sprite 1 (By)
2112 //
2113 // Spline with no tension (tension==0)
2114 //
2115
2116 auto action = CardinalSplineBy::create(3, array, 0);
2117 auto reverse = action->reverse();
2118
2119 auto seq = Sequence::create(action, reverse, nullptr);
2120
2121 _tamara->setPosition(50, 50);
2122 _tamara->runAction(seq);
2123
2124 auto drawNode1 = DrawNode::create();
2125 drawNode1->setPosition(Vec2(50.0f,50.0f));
2126 drawNode1->drawCardinalSpline(array, 0, 100, Color4F(1.0f, 0.0f, 1.0f, 1.0f));
2127 this->addChild(drawNode1);
2128
2129 //
2130 // sprite 2 (By)
2131 //
2132 // Spline with high tension (tension==1)
2133 //
2134
2135 auto action2 = CardinalSplineBy::create(3, array, 1);
2136 auto reverse2 = action2->reverse();
2137
2138 auto seq2 = Sequence::create(action2, reverse2, nullptr);
2139
2140 _kathia->setPosition(s.width/2, 50);
2141 _kathia->runAction(seq2);
2142
2143 auto drawNode2 = DrawNode::create();
2144 drawNode2->setPosition(Vec2(s.width/2, 50.0f));
2145 drawNode2->drawCardinalSpline(array, 1, 100, Color4F(1.0f, 0.0f, 1.0f, 1.0f));
2146 this->addChild(drawNode2);
2147}
2148
2150{
2151}
2152
2154{
2155 return "CardinalSplineBy / CardinalSplineTo";
2156}
2157
2159{
2160 return "Cardinal Spline paths. Testing different tensions for one array";
2161}
2162
2167{
2168
2169}
2170
2172{
2173
2174}
2175
2177{
2179
2180 this->centerSprites(3);
2181
2182 _tamara->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
2183 _grossini->runAction(RepeatForever::create(RotateBy::create(3.0f, -360.0f)));
2184 _kathia->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
2185
2186 this->schedule([&](float dt){
2187 log("Pausing");
2188 auto director = Director::getInstance();
2189
2190 _pausedTargets = director->getActionManager()->pauseAllRunningActions();
2191 }
2192 ,3 ,false ,0 ,"pause_key");
2193
2194 this->schedule([&](float dt) {
2195 log("Resuming");
2196 auto director = Director::getInstance();
2197 director->getActionManager()->resumeTargets(_pausedTargets);
2198 _pausedTargets.clear();
2199 }
2200 ,5 ,false ,0, "resume_key");
2201}
2202
2203std::string PauseResumeActions::title() const
2204{
2205 return "PauseResumeActions";
2206}
2207
2209{
2210 return "All actions pause at 3s and resume at 5s";
2211}
2212
2213//------------------------------------------------------------------
2214//
2215// ActionResize
2216// Works on all nodes where setContentSize is effective.
2217// But it's mostly useful for nodes where 9-slice is enabled
2218//
2219//------------------------------------------------------------------
2221{
2223
2224 _grossini->setVisible(false);
2225 _tamara->setVisible(false);
2226 _kathia->setVisible(false);
2227
2228 Size widgetSize = getContentSize();
2229
2230 Text* alert = Text::create("ImageView Content ResizeTo ResizeBy action. \nTop: ResizeTo/ResizeBy on a 9-slice ImageView \nBottom: ScaleTo/ScaleBy on a 9-slice ImageView (for comparison)", "fonts/Marker Felt.ttf", 14);
2231 alert->setColor(Color3B(159, 168, 176));
2232 alert->setPosition(Vec2(widgetSize.width / 2.0f,
2233 widgetSize.height / 2.0f - alert->getContentSize().height * 1.125f));
2234
2235 addChild(alert);
2236
2237 // Create the imageview
2238 Vec2 offset(0.0f, 50.0f);
2239 ImageView* imageViewResize = ImageView::create("cocosui/buttonHighlighted.png");
2240 imageViewResize->setScale9Enabled(true);
2241 imageViewResize->setContentSize(Size(50.0f, 40.0f));
2242 imageViewResize->setPosition(Vec2((widgetSize.width / 2.0f) + offset.x,
2243 (widgetSize.height / 2.0f) + offset.y));
2244
2245 auto resizeDown = cocos2d::ResizeTo::create(2.8f, Size(50.0f, 40.0f));
2246 auto resizeUp = cocos2d::ResizeTo::create(2.8f, Size(300.0f, 40.0f));
2247
2248 auto resizeByDown = cocos2d::ResizeBy::create(1.8f, Size(0.0f, -30.0f));
2249 auto resizeByUp = cocos2d::ResizeBy::create(1.8f, Size(0.0f, 30.0f));
2250 addChild(imageViewResize);
2251 auto rep = RepeatForever::create(Sequence::create(resizeUp, resizeDown, resizeByDown, resizeByUp, nullptr));
2252 imageViewResize->runAction(rep);
2253
2254 // Create another imageview that scale to see the difference
2255 ImageView* imageViewScale = ImageView::create("cocosui/buttonHighlighted.png");
2256 imageViewScale->setScale9Enabled(true);
2257 imageViewScale->setContentSize(Size(50.0f, 40.0f));
2258 imageViewScale->setPosition(Vec2(widgetSize.width / 2.0f,
2259 widgetSize.height / 2.0f));
2260
2261 auto scaleDownScale = cocos2d::ScaleTo::create(2.8f, 1.0f);
2262 auto scaleUpScale = cocos2d::ScaleTo::create(2.8f, 6.0f, 1.0f);
2263
2264 auto scaleByDownScale = cocos2d::ScaleBy::create(1.8f, 1.0f, 0.25f);
2265 auto scaleByUpScale = cocos2d::ScaleBy::create(1.8f, 1.0f, 4.0f);
2266 addChild(imageViewScale);
2267 auto rep2 = RepeatForever::create(Sequence::create(scaleUpScale, scaleDownScale, scaleByDownScale, scaleByUpScale, nullptr));
2268 imageViewScale->runAction(rep2);
2269}
2270
2271std::string ActionResize::subtitle() const
2272{
2273 return "ResizeTo / ResizeBy";
2274}
2275
2276//------------------------------------------------------------------
2277//
2278// ActionRemoveSelf
2279//
2280//------------------------------------------------------------------
2282{
2284
2286
2287 auto action = Sequence::create(
2288 MoveBy::create( 2, Vec2(240.0f,0.0f)),
2289 RotateBy::create( 2, 540),
2290 ScaleTo::create(1,0.1f),
2291 RemoveSelf::create(),
2292 nullptr);
2293
2294 _grossini->runAction(action);
2295}
2296
2298{
2299 return "Sequence: Move + Rotate + Scale + RemoveSelf";
2300}
2301
2302//------------------------------------------------------------------
2303//
2304// ActionFloat
2305//
2306//------------------------------------------------------------------
2308{
2310
2311 centerSprites(3);
2312
2313 auto s = Director::getInstance()->getWinSize();
2314
2315 // create float action with duration and from to value, using lambda function we can easily animate any property of the Node.
2316 auto actionFloat = ActionFloat::create(2.f, 0, 3, [this](float value) {
2317 _tamara->setScale(value);
2318 });
2319
2320 float grossiniY = _grossini->getPositionY();
2321
2322 auto actionFloat1 = ActionFloat::create(3.f, grossiniY, grossiniY + 50, [this](float value) {
2323 _grossini->setPositionY(value);
2324 });
2325
2326 auto actionFloat2 = ActionFloat::create(3.f, 3, 1, [this] (float value) {
2327 _kathia->setScale(value);
2328 });
2329
2330 _tamara->runAction(actionFloat);
2331 _grossini->runAction(actionFloat1);
2332 _kathia->runAction(actionFloat2);
2333}
2334
2337 centerSprites(0);
2338
2339 auto origin = cocos2d::Director::getInstance()->getVisibleOrigin();
2340 auto visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
2341
2342 _count = 0;
2343
2344 auto counterLabel = Label::createWithTTF("0", "fonts/Marker Felt.ttf", 16.0f);
2345 counterLabel->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
2346 addChild(counterLabel);
2347
2348 auto func = CallFunc::create([this, counterLabel]{
2349 _count++;
2350 std::ostringstream os;
2351 os << _count;
2352 counterLabel->setString(os.str());
2353 });
2354
2355 runAction(Spawn::create(func, func, nullptr));
2356}
2357
2358std::string Issue14936_1::subtitle() const {
2359 return "Counter should be equal 2";
2360}
2361
2364 centerSprites(0);
2365
2366 auto origin = cocos2d::Director::getInstance()->getVisibleOrigin();
2367 auto visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
2368
2369 _count = 0;
2370 auto counterLabel = Label::createWithTTF("0", "fonts/Marker Felt.ttf", 16.0f);
2371 counterLabel->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
2372 addChild(counterLabel);
2373
2374 auto func = CallFunc::create([this, counterLabel] {
2375 _count++;
2376 std::ostringstream os;
2377 os << _count;
2378 counterLabel->setString(os.str());
2379 });
2380
2381 runAction(Sequence::create(TargetedAction::create(this, func), DelayTime::create(0.2f), nullptr));
2382}
2383
2384std::string Issue14936_2::subtitle() const {
2385 return "Counter should be equal 1";
2386}
2387
2388std::string Issue14936_2::title() const {
2389 return "Issue 14936 - Sequence";
2390}
2391
2392std::string Issue14936_1::title() const {
2393 return "Issue 14936 - Action Interval";
2394}
2395
2396std::string ActionFloatTest::subtitle() const
2397{
2398 return "ActionFloat";
2399}
2400
2401
2402
2403//------------------------------------------------------------------
2404//
2405// SequenceWithFinalInstant
2406//
2407//------------------------------------------------------------------
2409{
2411
2412 _manager = new cocos2d::ActionManager();
2413
2414 _target = cocos2d::Node::create();
2415 _target->setActionManager( _manager );
2416 _target->retain();
2417 _target->onEnter();
2418
2419 bool called( false );
2420 const auto f
2421 ( [ &called ]() -> void
2422 {
2423 cocos2d::log("Callback called.");
2424 called = true;
2425 } );
2426
2427 const auto action =
2428 cocos2d::Sequence::create
2429 (cocos2d::DelayTime::create(0.05f),
2430 cocos2d::CallFunc::create(f),
2431 nullptr);
2432
2433 _target->runAction(action);
2434 _manager->update(0);
2435 _manager->update(0.05f - FLT_EPSILON);
2436
2437 if ( action->isDone() && !called )
2438 assert(false);
2439
2440 _manager->update(FLT_EPSILON);
2441
2442 if ( action->isDone() && !called )
2443 assert(false);
2444}
2445
2447{
2448 TestCase::onExit();
2449 _target->onExit();
2450 _target->release();
2451 _manager->release();
2452}
2453
2455{
2456 return "Instant action should not crash";
2457}
2458
2459//------------------------------------------------------------------
2460//
2461// Issue18003
2462//
2463//------------------------------------------------------------------
2464
2466{
2468
2469 _manager = new ActionManager();
2470
2471 _target = Node::create();
2472 _target->setActionManager(_manager);
2473 _target->retain();
2474 _target->onEnter();
2475
2476 // instant action + interval action
2477
2478 const auto f
2479 ( []() -> void
2480 {
2481 // do nothing
2482 });
2483
2484 auto action = Sequence::create(CallFunc::create(f),
2485 DelayTime::create(1),
2486 nullptr);
2487
2488 _target->runAction(action);
2489 _manager->update(0);
2490 _manager->update(2);
2491
2492 assert(action->isDone());
2493
2494 _target->stopAction(action);
2495
2496 // instant action + instant action
2497 action = Sequence::create(CallFunc::create(f),
2498 CallFunc::create(f),
2499 nullptr);
2500 _target->runAction(action);
2501 _manager->update(0);
2502 _manager->update(1);
2503 assert(action->isDone());
2504 _target->stopAction(action);
2505
2506 // interval action + instant action
2507 action = Sequence::create(DelayTime::create(1),
2508 CallFunc::create(f),
2509 nullptr);
2510 _target->runAction(action);
2511 _manager->update(0);
2512 _manager->update(2);
2513 assert(action->isDone());
2514 _target->stopAction(action);
2515
2516 // interval action + interval action
2517 action = Sequence::create(DelayTime::create(1), DelayTime::create(1), nullptr);
2518 _target->runAction(action);
2519 _manager->update(0);
2520 _manager->update(3);
2521 assert(action->isDone());
2522 _target->stopAction(action);
2523}
2524
2526{
2527 TestCase::onExit();
2528 _target->onExit();
2529 _target->release();
2530 _manager->release();
2531}
2532
2533std::string Issue18003::subtitle() const
2534{
2535 return "issue18003: should not crash";
2536}
USING_NS_CC
Definition: ActionsTest.cpp:36
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
virtual void onExit() override
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::EventListenerCustom * _frameDisplayedListener
Definition: ActionsTest.h:186
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
void doRemoveFromParentAndCleanup(Node *sender, bool cleanup)
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void onEnter() override
void callback(Node *sender)
void callback3(Node *pTarget, long data)
void callback2(Node *pTarget)
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string title() const override
virtual ~ActionCatmullRomStacked()
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void runActionsInSprite(cocos2d::Sprite *sprite) override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void runActionsInSprite(cocos2d::Sprite *sprite) override
virtual std::string title() const override
virtual std::string title() const override
virtual void runActionsInSprite(cocos2d::Sprite *sprite) override
virtual std::string subtitle() const override
virtual void onExit() override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
void repeatForever(Node *pTarget)
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
void callback2(Node *sender)
void callback3(Node *sender, long data)
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void addNewSpriteWithCoords(cocos2d::Vec2 p)
virtual void onEnter() override
virtual void runActionsInSprite(cocos2d::Sprite *sprite)
virtual std::string title() const override
virtual std::string subtitle() const override
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
void centerSprites(unsigned int numberOfSprites)
cocos2d::Sprite * _grossini
Definition: ActionsTest.h:37
virtual void onEnter() override
cocos2d::Sprite * _tamara
Definition: ActionsTest.h:38
void alignSpritesLeft(unsigned int numberOfSprites)
cocos2d::Sprite * _kathia
Definition: ActionsTest.h:39
virtual std::string title() const override
virtual void onExit() override
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
void printLog2()
virtual void onEnter() override
void printLog3()
void printLog4()
void printLog1()
virtual std::string title() const override
virtual void onExit() override
cocos2d::Sprite * _spriteTmp
Definition: ActionsTest.h:470
void log(Node *sender)
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string title() const override
virtual void onEnter() override
void logSprRotation(cocos2d::Sprite *sender)
virtual std::string subtitle() const override
int _testInteger
Definition: ActionsTest.h:529
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
void incrementIntegerCallback(void *data)
void incrementInteger()
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
cocos2d::ActionManager * _manager
Definition: ActionsTest.h:649
cocos2d::Node * _target
Definition: ActionsTest.h:650
virtual void onEnter() override
virtual void onExit() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual ~PauseResumeActions()
cocos2d::Vector< Node * > _pausedTargets
Definition: ActionsTest.h:579
virtual std::string title() const override
virtual void onExit() override
cocos2d::Node * _target
Definition: ActionsTest.h:635
virtual std::string subtitle() const override
virtual void onEnter() override
cocos2d::ActionManager * _manager
Definition: ActionsTest.h:634
virtual void onEnter() override
Definition: BaseTest.cpp:430
static cocos2d::Rect getVisibleRect()
Definition: VisibleRect.cpp:39
static cocos2d::Vec2 center()
Definition: VisibleRect.cpp:69
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63
static const char s_pathSister1[]
Definition: testResource.h:29
static const char s_pathSister2[]
Definition: testResource.h:30
static const char s_pathGrossini[]
Definition: testResource.h:28