有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Libgdx Box2D的速度还不够快

我有一个长方形,我想快速移动,但无论出于什么原因,我使用的更快的速度似乎仍然很慢。我做错了什么?我还把一个圆圈从上面扔到了一个表面上,即使我使劲玩弄重力,它也会像气球一样落下

一些声明

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

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

世界=新世界(新矢量2(0,-50),真)

我的物体移动到的地面

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

有人建议加快这方面的行动吗

我一直在使用1280×720的屏幕,但我从其他来源看到更小更好,所以我缩小到640×260,但仍然不是我想要的性能。我真的应该多小


共 (1) 个答案

  1. # 1 楼答案

    来自Box2d Manual(第2.2节):

    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