Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

Have you tried something like:

if (moveRight.active==YES) 
{
      b2Vec2 force=b2Vec2(4,ballBody.yForce);
      ballBody->SetLinearVelocity(force);                
}

if(moveRight.active==NO)
{
      b2Vec2 force=b2Vec2(0,ballBody.yForce);
      ballBody->SetLinearVelocity(force); 
} 

Note, I haven't used cocos2D, so I don't know how to properly get the y force (so I use ballBody.yForce, replace that with the correct code). I do recommend using the existing y force there, unless you want your jump to stop from x movement (same goes for your jump). I also find it strange that applying a force of 0 stops the ball, but you said that works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.