cocos2dx-5.动作

在这里插入图片描述
重点: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个参数)同理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值