I have some problem with CCMoveTo:
id actionMove = [CCMoveTo actionWithDuration:3 position:ccp(pointBoard[x][y].x,pointBoard[x][y].y)];
for example my sprite start move from ccp(20,460)
and move to ccp(20,0)
it's ok. But when sprite need to move to ccp(20,200)
than movement speed become slower.
I need to move sprite with the same speed. How can i do it?
Thanks.
You need to calculate the 'distance' between your [start] and [end] points and then you can calculate the 'duration' so that your sprite moves with constant speed. Something like,
float speed = 1; // here you define the speed that you want to use.
CGPoint start = sprite.position; // here you will get the current position of your sprite.
CGPoint end = ccp(pointBoard[x][y].x,pointBoard[x][y].y);
float distance = ccpDistance(start, end); // now you have the distance
float duration = distance/speed; // here you find the duration required to cover the distance at constant speed
Now you can call the CCMoveTo function and provide above calculated duration to make your sprite move at same speed.
Hope it helps..!!
To keep your movement speed constant for all distances, define a speed you need to move the sprite with and use the speed-time-distance formula you once learned as a child in your physics class to find an unknown from the three.
float speed = 50.0f;
id duration = ccpDistance(sprite.position, pointBoard[x][y]) / speed;
id moveAction = [CCMoveTo actionWithDuration:duration position:pointBoard[x][y]];
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