其实就是按照顺序来执行动作指令。
1 bool HelloWorld::init() 2 { 3 if (!Layer::init()) 4 { 5 return false; 6 } 7 8 Size visibleSize = Director::getInstance()->getVisibleSize(); 9 Sprite *label = Sprite::create("what.png"); 10 label->setPosition(visibleSize.width / 2, visibleSize.height / 2); 11 addChild(label); 12 auto listener = EventListenerTouchOneByOne::create(); 13 listener->onTouchBegan = [label](Touch *t, Event *e){ 14 15 if (label->getBoundingBox().containsPoint(t->getLocation())){ 16 //label->runAction(MoveTo::create(1, Point(100, 100))); 17 //label -> runAction(MoveBy::create(0.1, Point(-20, -20))->reverse()); 18 //label->runAction(Spawn::create(MoveBy::create(1, Point(100, 100)), 19 // RotateBy::create(1, 360), NULL)); 20 label->runAction(Sequence::create(MoveBy::create(1, Point(100, 21 100)), RotateBy::create(1, 360), NULL)); //此处创建,点击先执行移动,再执行旋转,再次点击再移动,接着旋转 22 } 23 return false; 24 }; 25 Director::getInstance()->getEventDispatcher()-> 26 addEventListenerWithSceneGraphPriority(listener,label); 27 //放这里直接执行 28 //label->runAction(RotateBy::create(1, 180)); 29 //label->runAction(Repeat::create(RotateBy::create(1,180),3)); 30 //label->runAction(RepeatForever::create(RotateBy::create(1, 360))); 31 return true; 32 }
一大堆注释代码可以无视,放在下面位置的话直接执行。