0

我定义了以下主体:

    //net
    netDef = new BodyDef();
    netDef.position.set(new Vector2((Gdx.graphics.getWidth() / 2) * WORLD_TO_BOX , 158f * WORLD_TO_BOX));
    netBody = world.createBody(netDef);
    PolygonShape netShape = new PolygonShape();
    netShape.setAsBox(10f * WORLD_TO_BOX, 125f * WORLD_TO_BOX);
    netBody.createFixture(netShape, 0f);
    netShape.dispose();

连同以下批次抽签:

batch.draw(slimeTexture, netBody.getPosition().x * BOX_TO_WORLD, netBody.getPosition().y * BOX_TO_WORLD, 10f/2, 125f/2, 10f, 125f, /*scaleX*/1, /*scaleY*/1, /*rotation*/ netBody.getAngle() * MathUtils.radiansToDegrees, 0, 0, 10, 125, /*flipX*/false, /*flipY*/false);

但我的最终结果是这样的:

http://s16.postimg.org/i1bh331th/show.png

我用一个圆圈做了这个,它就像一个魅力,但我不明白这里做错了什么。有人愿意解释我搞砸了什么,所以我不会再犯了?

4

1 回答 1

0

当你使用 setAsBox .. 你必须提供一半的高度和一半的宽度,这就是为什么你的文本是绘制大小的 1/4 ......默认情况下,当你绘制框时,身体原点是中心,所以你必须 setPosition文本到

   ( bodyPOs.x - width/2, bodyPos.y - height/2);




   netDef = new BodyDef();
   netDef.position.set(new Vector2((Gdx.graphics.getWidth() / 2) * WORLD_TO_BOX , 158f *    WORLD_TO_BOX));
    netBody = world.createBody(netDef);
    PolygonShape netShape = new PolygonShape();
    netShape.setAsBox(10f * WORLD_TO_BOX, 125f * WORLD_TO_BOX);  // wrong
    netShape.setAsBox(10f * WORLD_TO_BOX/2f, 125f * WORLD_TO_BOX/2f);  // divide by 2(right)

netBody.createFixture(netShape, 0f);
netShape.dispose();


 batch.draw(slimeTexture, netBody.getPosition().x * BOX_TO_WORLD - /*width/2f*/ 10/2,    netBody.getPosition().y * BOX_TO_WORLD - /**height/2*/ 125/2f, 10f/2, 125f/2, 10f, 125f, /*scaleX*/1, /*scaleY*/1, /*rotation*/ netBody.getAngle() * MathUtils.radiansToDegrees, 0, 0, 10, 125, /*flipX*/false, /*flipY*/false);
于 2013-07-19T10:32:20.533 回答