其实主要是为了看一下动作是否结束
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)), RotateBy::create(1, 360), NULL)); 19 //label->runAction(Sequence::create(MoveBy::create(1, Point(100,100)), RotateBy::create(1, 360), NULL)); 20 label->runAction(Sequence::create( 21 MoveBy::create(1,Point(100,100)),//第一个动作 22 RotateBy::create(1,360),//第二个动作 23 CallFunc::create([]{ 24 MessageBox("Action complete", "complete");//消息框 25 }), NULL)); 26 } 27 return false; 28 }; 29 Director::getInstance()->getEventDispatcher()-> 30 addEventListenerWithSceneGraphPriority(listener,label); 31 32 //label->runAction(RotateBy::create(1, 180)); 33 //label->runAction(Repeat::create(RotateBy::create(1,180),3)); 34 //label->runAction(RepeatForever::create(RotateBy::create(1, 360))); 35 return true; 36 }
懒得删了其余的注释代码了。。。具体还是没玩的太流利。。。以后弄得比较明白了在回头看看
原文:http://www.cnblogs.com/aprillie/p/5022662.html