cocos2dbeginner
cocos2dbeginner

Reputation: 13

How can I get the velocity of my sprite?

I want to knew the velocity of my sprite. How can I do that? Is there any formula(is that the word?)...

If you only knew the answer with cocos2d. No problem I can cocos2d!

PS: My English isn't so well.

Upvotes: 0

Views: 146

Answers (2)

Srinivas
Srinivas

Reputation: 1059

CGPoint diff = ccpSub(new_location, oldTouchLocation);
CGPoint currentpos = [para6 position];
CGPoint destination = ccpAdd(currentpos, diff);
if (destination.x < 80 && destination.x > 20)
{
 Velocity = (20 + (80-destination.x))*1.8 ;
}

above is the sample example calculating velocity for my plunger

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135548

Velocity is defined as distance divided by time. So you would divide the pixels your sprite traveled within a given time period by the time elapsed.

Upvotes: 1

Related Questions