Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to slow down CCMoveTo?

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.

like image 830
Pablo Avatar asked Mar 22 '23 21:03

Pablo


2 Answers

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.

like image 79
Ricardo Sanchez-Saez Avatar answered Apr 08 '23 08:04

Ricardo Sanchez-Saez


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 .

like image 42
giorashc Avatar answered Apr 08 '23 08:04

giorashc