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:2 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:2 position:ccp(s.width-40,s.height-40)];
id actionBy = [CCMoveBy actionWithDuration:2 position:ccp(80,80)];
[sprite1runAction:actionTo];
[sprite2 runAction:actionBy];
ReverseAction(回退动作)
几乎所有的actions都有reverse的实现,从根本上说使用reverse就是创建了一个新的actions
例子:
id move=[CCMoveBy actionWithDuration:2 position:ccp(80, 80)];
id move_reverse = [move reverse];
这个move_reverse动作会在2秒内,返回到相对位置的ccp(-80,-80)