Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.

Actions: Ease

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:

  • In actions: The acceleration is at the beginning of the action
  • Out actions: The acceleration is at the end of the action
  • InOut actions: The acceleration is at the beginning and at the end.

For more information about easing or tweening actions, visit any of these pages:

Ease actions

They accelerate the inner action using this formula:

-(void) update:(ccTime) t
{
   [inner update: powf(t,rate)];
}

Variations:

  • CCEaseIn: acceleration at the beginning
  • CCEaseOut: acceleration at the end
  • CCEaseInOut: acceleration at the beginning / end

The 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];

EaseExponential actions

Available exponential actions:

  • CCEaseExponentialIn
  • CCEaseExponentialOut
  • CCEaseExponentialInOut

Example:

id scaleAction = [CCScaleTo actionWithDuration:2.5 scale:.8];
id easeAction = [CCEaseExponentialIn actionWithAction:scaleAction];
[label runAction: easeAction];

FIXME

EaseSine actions

Available sine actions:

  • CCEaseSineIn
  • CCEaseSineOut
  • CCEaseSineInOut

Examples:

// 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];

EaseElastic actions

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:

  • CCEaseElasticIn
  • CCEaseElasticOut
  • CCEaseElasticInOut

Examples:

// '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

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:

  • CCEaseBounceIn
  • CCEaseBounceOut
  • CCEaseBounceInOut

Examples:

// 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];

EaseBack actions

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:

  • CCEaseBackIn
  • CCEaseBackOut
  • CCEaseBackInOut

Examples:

// 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];

Actions: Speed

Speed 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)
prog_guide/actions_ease.txt · Last modified: 2011/06/13 02:02 by ctxppc
Trace: 0_99_0 start migrating_to_0_9 cocos2d_and_uikitlayer iphone_recommended_reading 0_8_1_beta 0_99_0_rc cookbook templates actions_ease
Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0