雪碧身体不能停止 [英] Sprite Body can not stop

查看:226
本文介绍了雪碧身体不能停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有另一个问题关于跳跃雪碧体。在我的代码中我使用moveLeft和moveRight按钮,当我按下moveRight按钮使用以下代码

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);                
    }

它的移动完美,当我释放这个按钮比sprite body停止使用下面的代码

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); 
} 

但是当我把这个else部分,然后跳转不能做。我的跳转代码如下

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());
                }

如果我删除else部分,那么跳转将执行完成,但sprite body不能停止后释放按钮。

If i remove else part then jump will perform complete but sprite body can not stop after release button.

那么该怎么做

提前感谢

推荐答案

我得到了答案。
我们创建身体,首先检查它是圆形或多边形,因为圆形身体不能有滚动阻力,所以在这种情况下,我们不需要手动使用linearVelocity为0.
使用摩擦全身停止自动除了圈子身体。

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.

这篇关于雪碧身体不能停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆