Libgdx Box2D速度不够快 [英] Libgdx Box2D Velocity is just not fast enough

查看:209
本文介绍了Libgdx Box2D速度不够快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要快速移动的矩形,但是无论出于什么原因,我使用的更快的速度似乎仍然很慢.我究竟做错了什么?我还从上方将一个圆圈放到了表面上,即使在强力的作用下,它也像气球一样掉下来……

I have a rectangle that I would like to move fast but for what ever reason the faster velocity I use still seems slow. What am I doing wrong? I have also dropped a circle from above onto a surface and even tough I play with gravity it comes down like a ballon...

一些声明

float velocity = 10000000f;
static final float BOX_STEP=1/60f;  
static final int BOX_VELOCITY_ITERATIONS=6;  
static final int BOX_POSITION_ITERATIONS=2;  

重力,尝试了一切,它们似乎都很烂

Gravity, tried everything and they all seem to suck

world = new World(new Vector2(0,-50),true);

world = new World(new Vector2(0, -50), true);

我的物体正在移动的地面

The ground my object is moving onto

    //ground
    BodyDef groundBodyDef =new BodyDef();  
    groundBodyDef.position.set(new Vector2(0, camera.viewportHeight * .08f));  
    Body groundBody = world.createBody(groundBodyDef);  
    PolygonShape groundBox = new PolygonShape();  
    groundBox.setAsBox((camera.viewportWidth) * 2, camera.viewportHeight * .08f);  
    groundBody.createFixture(groundBox, 0.0f);   

然后是我的对象:

    //ball
    bodyDef = new BodyDef();  
    bodyDef.type = BodyType.DynamicBody;  
    bodyDef.position.set(new Vector2(camera.viewportWidth * .2f, camera.viewportHeight * .75f));  
    body = world.createBody(bodyDef);  
    CircleShape dynamicCircle = new CircleShape();  
    dynamicCircle.setRadius(camera.viewportWidth * .035f);  
    FixtureDef fixtureDef = new FixtureDef();  
    fixtureDef.shape = dynamicCircle;  
    fixtureDef.density = 0.5f;  
    fixtureDef.friction = 0.5f;  
    fixtureDef.restitution = 0.8f;  
    body.createFixture(fixtureDef); 
    body.setLinearVelocity(0,-100);

    //slime boy
    BodyDef bodyBoxDef = new BodyDef();  
    bodyBoxDef.type = BodyType.DynamicBody;  
    bodyBoxDef.position.set(new Vector2(camera.viewportWidth * .08f,camera.viewportHeight * .191f));  
    bodyBox = world.createBody(bodyBoxDef);  
    PolygonShape slimeBox = new PolygonShape();  
    slimeBox.setAsBox(camera.viewportWidth * .04f, camera.viewportHeight * .03f);
    FixtureDef fixtureSlimeDef = new FixtureDef();  
    fixtureSlimeDef.shape = slimeBox;  
    fixtureSlimeDef.density = 1.0f;  
    fixtureSlimeDef.friction = 0.0f;  
    fixtureSlimeDef.restitution = 0.0f;  
    bodyBox.createFixture(fixtureSlimeDef);  

    debugRenderer = new Box2DDebugRenderer(); 

    body.applyTorque(1000000000);
    bodyBox.setFixedRotation(true);
    bodyBox.setBullet(true);

有人建议加快这一进程吗?

Any one have suggestions to speed up all movement in this?

我一直在使用1280 x 720的屏幕,但是从其他来源看,屏幕越小越好,因此我将屏幕缩小到640 x 260,但仍然不是我想要的性能.我真的应该走多小?

I have been using a screen 1280 by 720 but I saw from other sources smaller is better so I scaled down to 640 by 260 but still not the preformance I want. How small should I really go?

推荐答案

来自 Box2d手册(第2.2节):

Box2D已调整为米,千克和秒.所以你可以考虑 范围以米为单位.通常,当对象存在时,Box2D效果最佳 是典型的现实世界对象的大小.例如,桶是 大约1米高.由于浮点数的限制 算术,使用Box2D对冰川或灰尘的运动进行建模 粒子不是一个好主意.

Box2D is tuned for meters, kilograms, and seconds. So you can consider the extents to be in meters. Box2D generally works best when objects are the size of typical real world objects. For example, a barrel is about 1 meter tall. Due to the limitations of floating point arithmetic, using Box2D to model the movement of glaciers or dust particles is not a good idea.

请参见 https://stackoverflow.com/a/4556714/960524

这篇关于Libgdx Box2D速度不够快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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