1
votes

So I have this texture I am drawing, and the origin is bottom left corner. It looks ok until I have to rotate it.

Without rotation:

enter image description here

With Rotation:

enter image description here

I also tried moving the origin to the center, its better but not perfect:

enter image description here

Here is the code I have used at the last one:

    Sprite b = new Sprite(slimeTexture);
    b.setPosition(slimeBody.getPosition().x * BOX_TO_WORLD, slimeBody.getPosition().y * BOX_TO_WORLD);
    b.setSize(1.6f * BOX_TO_WORLD, (1.6f * BOX_TO_WORLD) / 2.7f);
    b.setRotation(slimeBody.getAngle() * MathUtils.radiansToDegrees);
    b.setOrigin((1.6f * BOX_TO_WORLD) /2f, ((1.6f * BOX_TO_WORLD) / 2.7f)/2f);

Any ideas why its not fitting perfectly? I tought moving the origin would do it but I have never been so wrong in my entire life.

1
Ok I found out if I do this: code b.setOrigin((1.6f * BOX_TO_WORLD) /28f, ((1.6f * BOX_TO_WORLD) / 2.7f)/28f); The rotation will be correct but makes no logical sense of putting the origin at 11.3,4.2 makes this work. Any one to chime in why this has happened? Or what am doing wrong?user1001506
Fixed it: had to make it b.setOrigin(0, 0); which makes sense but by default it should be that but then again I am known to be wrong a lotuser1001506
Provide the coordinates or your fixtures, please.Pavel

1 Answers

0
votes

For rotation use:

sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);

For positioning, set origin to the left corner. ref.