0
votes

I have the following body defined:

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

Along with the following batch draw:

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

But my end result is this:

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

I did this with a circle and it worked like a charm but I don't understand what am doing wrong here. Any one care to explain what I messed up so I won't do it again?

1

1 Answers

0
votes

when u use setAsBox.. you have to provide half height and half width, thats why your textue is 1/4 the size drawn... And by default when you are drawing box then the body origin is center so you have to setPosition of textue to

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