Actions

Actions are lightweight classes that are used on nodes to perform certain, well, actions. They allow you to move, rotate, scale, tint, fade, and do a lot of other things with a node.
There are only three actions that directly derive from CCAction:
CCFollow (allows a node to follow another node)
CCRepeatForever (repeats an action indefinitely)
CCSpeed (changes the update frequency of an action while it is running)

eg: [label runAction:[CCFollow actionWithTarget:playerSprite]]; //to have a label follow the player character sprite    

Interval Actions    
在某个时间内作actioin.

// have myNode move to 100, 200 and arrive there in 3 seconds
CCMoveTo* move = [CCMoveTo actionWithDuration:3 position:CGPointMake(100, 200)]; 
[myNode runAction:move]; 

Action Sequences    

Here’s how to cycle a label’s colors from red to blue to green:

CCTintTo* tint1 = [CCTintTo actionWithDuration:4 red:255 green:0 blue:0]; 
CCTintTo* tint2 = [CCTintTo actionWithDuration:4 red:0 green:0 blue:255]; 
CCTintTo* tint3 = [CCTintTo actionWithDuration:4 red:0 green:255 blue:0]; 
// actions only objects of interval actions.
CCSequence* sequence = [CCSequence actions:tint1, tint2, tint3, nil]; 
[label runAction:sequence]; 

Ease Actions    

// I want myNode to move to 100, 200 and arrive there in 3 seconds
CCMoveTo* move = [CCMoveTo actionWithDuration:3 position:CGPointMake(100, 200)]; 
// this time the node should slowly speed up and then slow down as it moves 
CCEaseInOut* ease = [CCEaseInOut actionWithAction:move rate:4];
[myNode runAction:ease]; 

Cocos2d implements the following CCActionEase classes: 
CCEaseBackIn, CCEaseBackInOut, CCEaseBackOut
CCEaseBounceIn, CCEaseBounceInOut, CCEaseBounceOut
CCEaseElasticIn, CCEaseElasticInOut, CCEaseElasticOut
CCEaseExponentialIn, CCEaseExponentialInOut, CCEaseExponentialOut 
CCEaseIn, CCEaseInOut, CCEaseOut
CCEaseSineIn, CCEaseSineInOut, CCEaseSineOut 

Grid Actions   

The specialty of the grid actions are three-dimensional effects such as the turning of a page (CCPageTurn3D; see Figure 3–16) or simulating waves and liquids (CCWaves, CCLiquid).
The downside is that the 3D effects may show visual artifacts unless you enable depth buffering, which requires more memory and has a negative impact on rendering performance, particularly on first- and second-generation devices.
Enable depth buffering:
//GL_DEPTH_COMPONENT16_OES for a 16-bit depth buffer or GL_DEPTH_COMPONENT24_OES for a //24-bit depth buffer 
EAGLView *glView = [EAGLView viewWithFrame:[window bounds] 
pixelFormat:kEAGLColorFormatRGB565
depthFormat:GL_DEPTH_COMPONENT16_OES]; 
Instant Actions    

The main reason that instant actions exist is because they are useful in action sequences. Sometimes in a sequence of actions you have to change a certain property of the node, such as visibility or position, and then continue with the sequence. Instant actions make this possible. True, they are rarely used—with one exception: CCCallFunc actions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值