Sprite Body can not stop

大城市里の小女人 提交于 2019-12-11 18:08:19

问题


Hey i have another 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


回答1:


I got the answer. I we create body and first check it is circle or polygon because circle body can not have rolling resistance so and in this case we don't need to stop manually using linearVelocity to 0. Using friction all body stop automatically excepting circle body.



来源:https://stackoverflow.com/questions/12190999/sprite-body-can-not-stop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!