Sprite Body can not stop
Posted
by
Diken
on Game Development
See other posts from Game Development
or by Diken
Published on 2012-08-30T11:05:43Z
Indexed on
2012/08/30
15:50 UTC
Read the original article
Hit count: 238
cocos2d-iphone
|box2d
Hey i have issue regarding jump sprite body. In my code i am using moveLeft and moveRight Button and when i am press moveRight Button using following code
if (moveRight.active==YES)
{
b2Vec2 force=b2Vec2(4,0);
ballBody->SetLinearVelocity(force);
}
Its move perfectly and When i release this Button than sprite body stop using following code
else
{
b2Vec2 force=b2Vec2(0,0);
ballBody->SetLinearVelocity(force);
}
But when i put this else part then jump can not done. My jump code is following
if (jumpSprite.active==YES)
{
NSLog(@"Jump Sprite");
b2Vec2 locationWorld;
locationWorld=b2Vec2(0.0f,4.0f);
double force=ballBody->GetMass();
ballBody->ApplyLinearImpulse(force*locationWorld, ballBody->GetWorldCenter());
}
If i remove else part then jump will perform complete but sprite body can not stop after release button.
So what to do??
Thanks in advance
© Game Development or respective owner