Ease actions are special composition actions that alter the time of the inner action.
In the Flash world they are often called Tweening or Easing actions.
These actions modify the speed of the inner action, but they don't modify the total running time. If the inner action lasts 5 seconds, then the total will continue to be 5 seconds.
The Ease actions alter the linearity of the time.
For example they can accelerate or decelerate the inner action.
These actions can be classified in 3 types:
For more information about easing or tweening actions, visit any of these pages:
They accelerate the inner action using this formula:
-(void) update:(ccTime) t { [inner update: powf(t,rate)]; }
Variations:
CCEaseIn: acceleration at the beginningCCEaseOut: acceleration at the endCCEaseInOut: acceleration at the beginning / endThe rate argument indicates the acceleration rate.
Example:
// acceleration at the beginning id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseIn actionWithAction:action rate:2]; [sprite runAction: ease]; // acceleration at the end id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseOut actionWithAction:action rate:2]; [sprite runAction: ease]; // acceleration at the beginning / end id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseInOut actionWithAction:action rate:2]; [sprite runAction: ease];
Available exponential actions:
CCEaseExponentialInCCEaseExponentialOutCCEaseExponentialInOutExample:
id scaleAction = [CCScaleTo actionWithDuration:2.5 scale:.8]; id easeAction = [CCEaseExponentialIn actionWithAction:scaleAction]; [label runAction: easeAction];
Available sine actions:
CCEaseSineInCCEaseSineOutCCEaseSineInOutExamples:
// Sine at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineIn actionWithAction:move]; [sprite runAction:action]; // Sine at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineOut actionWithAction:move]; [sprite runAction:action]; // Sine at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineInOut actionWithAction:move]; [sprite runAction:action];
These actions alters the time simulating an elastic. Elastic actions will use time values greater than 1 and lower than 0, so the inner action should be prepared to handle this special values.
Also some values will be triggered more than once (this function is not bijective), so again, the inner action should be prepared to handle this values.
Simple actions like CCMoveBy, CCScaleBy, CCRotateBy work OK with EaseElastic actions, but the CCSequence or CCSpawn actions might have unexpected results.
Available elastic actions:
CCEaseElasticInCCEaseElasticOutCCEaseElasticInOutExamples:
// 'period' is how elastic is the action. // recommended values: between 0.3 and 0.45 // Elastic at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticIn actionWithAction:move period:0.3f]; [sprite runAction: action]; // Elastic at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticOut actionWithAction:move period:0.3f]; [sprite runAction: action]; // Elastic at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticInOut actionWithAction:move period:0.3f]; [sprite runAction: action];
EaseBounce actions simulates a bouncing effect.
Some time values will be triggered more than once (this function is not bijective), so the inner action should be prepared to handle this values.
Simple actions like CCMoveBy, CCScaleBy, CCRotateBy work OK with EaseBounce actions, but the CCSequence or CCSpawn actions might have unexpected results.
Available bounce actions:
CCEaseBounceInCCEaseBounceOutCCEaseBounceInOutExamples:
// Bounce at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceIn actionWithAction:move]; [sprite runAction: action]; // Bounce at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceOut actionWithAction:move]; [sprite runAction: action]; // Bounce at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceInOut actionWithAction:move]; [sprite runAction: action];
Some time values will be triggered more than once (this function is not bijective), so the inner action should be prepared to handle this values.
Simple actions like CCMoveBy, CCScaleBy, CCRotateBy work OK with EaseBack actions, but the CCSequence or CCSpawn actions might have unexpected results.
Available Back actions:
CCEaseBackInCCEaseBackOutCCEaseBackInOutExamples:
// Back at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackIn actionWithAction:move]; [sprite runAction: action]; // Back at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackOut actionWithAction:move]; [sprite runAction: action]; // Back at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackInOut actionWithAction:move]; [sprite runAction: action];
The CCSpeed action modifies the duration of the inner action.
id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCSpeed actionWithAction: move speed:1.0f]; // no speed modification // but you can modify the speed later [action setSpeed: 2.5f]; // speed is 2.5 faster [action setSpeed: 0.5f]; // speed is 0.5 faster (it means 2 times slower)