6.【cocos2d翻译系列】Basic actions

Actions(动作)


actions是对于CCNode的对象有意义的。这些actions通常修改对象的一些属性,例如:位置,旋转角度,缩放比例,等。

如果这些属性实在一个时间段内修改的,那它们不是CCIntervalAction(慢慢地修改)就是CCInstantAction

(瞬时修改)


例如:

//Move a sprite 50 pixels to the right, and 10 pixels to the top over 2seconds.
[sprite runAction:[CCMoveBy actionWithDuration:position:ccp(50,10)]];


CCIntervalAction这个actions有几个好玩的属性:

They can be accelerated using the time-altered actions 

  • CCEaseIn
  • CCEaseOut
  • CCEaseInOut
  • CCSpeed
  • 等等(查看EaseActionsTest.m的例子获得更多地信息)

所有相对(relative)actions(以By结尾的),和所有绝对的actions(以To结尾)都有一个反过来的action

([action reverse]),这个方法会返回相反的执行路径的actions

你可以通过CCActionManager暂停或恢复所有的actions

//Pause actions

[[CCActionManager sharedManager]pauseAllActionsForTarget:sprite];

//resume actions

[[CCActionManager sharedManager]resumeAllActionsForTarget:sprite];



BasicActions(基本的动作)

基本动作就是修改基本的属性如下所示:

position

CCMoveBy  (移动)

CCMoveTo

CCJumpBy   (跳跃)

CCJumpTo

CCBezierBy   (贝塞尔曲线)

CCBezierTo

CCPlace

scale

CCScaleBy   (缩放)

CCScaleTo

rotation

CCRotateBy   (旋转)

CCRotateTo

visible

CCShow  

CCHide

CCBlink   (闪烁)

CCToggleVisibility

opacity

CCFadeIn  (淡入)

CCFadeOut  (淡出)

CCFadeTo

r,g, b

CCTintBy

CCTintTo

例子:

CGSizes= [[CCDirector sharedDirector]winSize];

id actionTo = [CCMoveTo actionWithDuration:position:ccp(s.width-40,s.height-40)];
id actionBy = [CCMoveBy actionWithDuration:position:ccp(80,80)];

[sprite1runAction:actionTo];

[sprite2 runAction:actionBy];



ReverseAction(回退动作)

几乎所有的actions都有reverse的实现,从根本上说使用reverse就是创建了一个新的actions

例子:

id move=[CCMoveBy actionWithDuration:position:ccp(8080)];

id move_reverse = [move reverse];

这个move_reverse动作会在2秒内,返回到相对位置的ccp(-80,-80)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值