我定义了以下正文:
//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
我用圆圈做了这个,它就像一个魅力,但我不明白这里做错了什么。任何人都在乎解释我搞砸了什么,所以我不会再这样做了?
答案 0 :(得分:0)
当你使用setAsBox ..你必须提供半高和半宽,这就是为什么你的textue是绘制的大小的1/4 ...默认情况下,当你绘图框时,身体原点是中心所以你有将textPosition设置为
( 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);