1
votes

I am trying to rotate a textureRegion, based on box2d body angle, using the spriteBatcher draw method:

SpriteBatch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height,float scaleX, float scaleY, float rotation)

However the resulting rotation looks like this

enter image description here I can't figure out what I am doing wrong, have tried a lot of different combinations of originX, originY and it is always broken. Tried to setting the origins to center of body, left bottom corner, and no luck.

Looked at the documentation, analzyed the SpriteBatch.class but its unclear to me what's the reason.

How to rotate the texture properly?

EDIT: I cannot use Sprite class, because the textureRegion that is being drawn is an animation frame and afaik you can't make animation frames out of Sprite class

2

2 Answers

1
votes

The origin is in bottom left corner of the image, put it in the center of the image. So make originX width/2 and originY height/2.

1
votes

Set polygonshape of box2d body like this

float width=x,height=y;

PolygonShape polygonShape=new PolygonShape();
polygonShape.setAsBox(width/2, height/2,new Vector2(width/2,height/2),0);

setAsBox method of PolygonShape is overloaded.