cocos2d-x-3.x 动作(4)混合动作

其实说白了就是同时进行多动,比如混合一下移动和旋转

 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));    //此处创建,第一个指将其移动到坐标点,第二个是1s360度,NULL必须加上,否则出错
20         }                                                              //放着这里点一次执行一次可以执行多次
21         return false;
22     };
23     Director::getInstance()->getEventDispatcher()->
24         addEventListenerWithSceneGraphPriority(listener,label);
25                                                                                    //如果放在这里只能直接执行一次
26     //label->runAction(RotateBy::create(1, 180));
27     //label->runAction(Repeat::create(RotateBy::create(1,180),3));
28     //label->runAction(RepeatForever::create(RotateBy::create(1, 360)));
29     return true;
30 }

 

posted on 2015-12-05 23:52  四月厨  阅读(251)  评论(0编辑  收藏  举报