Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom easing action with Cocos2D-iphone

How would one go about creating a custom action in Cocos2D that was able to perform a 'callback' over time, making each call to the callback progressively longer than the last call to it (using something similar to the EaseExponentialOut action already provided with Cocos2D.

Something similar to this: (which does not work)

id sequence = [Sequence actions: [CallFunc actionWithTarget: self selector: @selector(spinTick)], [DelayTime actionWithDuration: 0.034f], nil];
id repeat = [Repeat actionWithAction: [sequence copy]  times: 18];
id ease = [EaseExponentialOut actionWithAction: [repeat copy]];
[ease setDuration:4];

id play = [CallFunc actionWithTarget:self selector:@selector(play)];
[self runAction: [Sequence actions: [ease copy], [play copy], nil]];

The above code executes the entire 'sequence', 18 times and then executes the 'play' callback at the end of the last sequence.

However, the EaseExponentialOut does not appear to have any affect at all on the 'repeat' action that is created - I had expected it to adjust the duration of the 'DelayTime' action inside of the 'sequence' action, but it does not appear to do this.

I also attempted to create my own custom action based on IntervalAction, but failed miserably.

like image 532
David Higgins Avatar asked Nov 05 '22 21:11

David Higgins


1 Answers

Apparently, the code above is functional, it was just my use of the timing in the durations. It was also not necessary to use 'copy', as the actions are usable as is.

If I increased my timing from 0.034 to something more along the lines of 0.25, then the result was closer to what I was hoping to see. Now I just have to play with the values for duration to get it 'just right'.

like image 166
David Higgins Avatar answered Nov 15 '22 12:11

David Higgins