2

我有一个矩形,我想快速移动,但出于某种原因,我使用的更快速度仍然看起来很慢。我究竟做错了什么?我还把一个圆圈从上面掉到了一个表面上,即使我在重力下玩得很艰难,它也会像气球一样掉下来......

一些声明

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

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

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

我的对象正在移动的地面

    //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 x 720 的屏幕,但我从其他来源看到越小越好,所以我缩小到 640 x 260,但仍然不是我想要的性能。我真的应该去多小?

4

1 回答 1

6

来自Box2d 手册(第 2.2 节):

Box2D 针对米、千克和秒进行了调整。因此,您可以考虑以米为单位的范围。Box2D 通常在对象与典型现实世界对象大小相同时效果最佳。例如,一个桶大约有 1 米高。由于浮点运算的限制,使用 Box2D 来模拟冰川或尘埃颗粒的运动并不是一个好主意。

https://stackoverflow.com/a/4556714/960524

于 2013-07-17T16:27:56.483 回答