I have CCMoveTo
action on sprite, which is moving it from one point to another. When user hits a button the sprite should slow down with ease and continue moving to target location with new speed. I have no clue how to make this happen.
Update. Actually I replaced CCMoveTo
with CCMoveBy
but question still same.
With the current implementation of CCEaseIn/CCEaseOut
actions, you can only ease the rate of actions from and to zero. This means that if you ease CCMoveBy/CCMoveTo
they will ease the movement speed from/to a standstill.
However, starting from cocos2d 2.1 CCMoveBy/CCMoveTo
are stackable. With this feature you can implement a workaround that results in the effect you want.
Setup and simulataneously run two CCMoveBy
actions for the sprite: actionA
will have the slower movement speed that you get after the button press. actionB
will have the speed corresponding to the difference of the faster speed and the slower speed.
Then, when the user presses the button, you can CCEeaseOut
actionB
(stop CCMoveBy
, and then launch it again with the desired CCEaseOut
). This will look like the sprite eases from the movement speed of actionA + actionB
to the speed of actionA
.
Despite this explanation, if you are implementing game controls that you want to precisely fine tune, it might be a better idea to avoid CCActions
and just update the sprite position frame-by-frame by implementing custom movement code.
You can use the EaseIn/Out action to get that effect :
id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)];
id ease = [CCEaseIn actionWithAction:action rate:2];
[sprite runAction: ease];
Taken from here
You can find different types of easing to suit your needs .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With