重点:CCActionInstant为立即动作,CCActionInterval为持续动作。
CCFollow为镜头跟踪,CCSpeed为修改node执行速度
1.CCActionInstant
FlipX:在X轴方向上旋转
FlipY:在Y轴方向上旋转
Sprite* a = Sprite::create("pig.png");
Sprite* b = Sprite::create("pig.png");
a->setPosition(ccp(150, visibleSize.height / 2));
b->setPosition(ccp(350, visibleSize.height / 2));
FlipX *flipx = FlipX::create(true);
b->runAction(flipx);
this->addChild(a);
this->addChild(b);
2.CCActionInterval
auto moveto = MoveBy::create(2.0f, ccp(700, visibleSize.height / 2));
a->runAction(moveto);
//moveto参数::1.动作时间2.移动位置
auto moveby = MoveBy::create(2.0f, ccp(700, visibleSize.height / 2));
b->runAction(moveby);
auto scaleto = ScaleTo::create(2.0f, 1.4, 1.4);
a->runAction(scaleto);
//scale参数:1.移动时间2.缩放比例
auto scaleby = ScaleBy::create(2.0f, 1.4, 1.4);
b->runAction(scaleby);
auto jumpto = JumpTo::create(2.0, ccp(500, 500), 50, 5);
a->runAction(jumpto);
//jumpto参数:1.动作时间2.移动位置3.每次移动高度4.移动次数
auto jumpby = JumpBy::create(2.0, ccp(500, 500), 50, 5);
b->runAction(jumpby);
auto rotateTo = RotateTo::create(2.0f, 40.0f);
mySprite->runAction(rotateTo);
auto rotateBy = RotateBy::create(2.0f, 40.0f);
mySprite->runAction(rotateBy);
By 算的是相对于节点对象的当前位置,To 算的是绝对位置,不考虑当前节点对象在哪。如果你想动作的表现是相对于 Node 当前位置的,就用 By,相对的想让动作的表现是按照坐标的绝对位置就用 To
组合动作:
1.闪烁
auto blink = Blink::create(1.0f, 3);闪烁时间和次数
a->runAction(blink);
2.重复动作
RepeatForever* forever = RepeatForever::create(jumpby);//动作参数
a->runAction(forever);
3.重复动作的次数
Repeat* repeat = Repeat::create(jumpby, 3)
4.同时执行的组合动作
auto action = Spawn::create(moveto, jumpby, NULL)
5.以顺序执行的组合动作
auto sque = Sequence::create(moveto, jumpby, NULL)
6.回调函数CallFunc(无参)
CallFunc* call = CallFunc::create(this, callfunc_selector(HelloWorld::jump));
auto sque = Sequence::create(moveto, call, NULL);
简单讲在移动之后的执行的动作,都写进回调函数罢了
变量和函数定义均在.h中定义
回调函数CallFuncN(1个参数)同理