how to set TextureRegion’s centre point to rotate around. (libGdx)

I’m trying to rotate a TextureRegion around its centre, however whenever I try to rotate it the rotation point is either the bottom corners of the Texture Region or a far part of the screen. this is the update method in my object class(the Texture Region will be emulating the movements of this Object.

public void update(float delta) {

   if (velocity.x < 0) {
        rotation -= 50*delta;

        if (rotation > 25) {
            rotation = 25;
        }
    }
    if (velocity.x > 0){
        rotation += 50*delta;

        if (rotation > 25) {
            rotation = 25;
        }
    }
}

this where I call the draw method to bring the Texture Region to screen

batcher.draw(AssetLoader.saum, sam.getX(), (gameHeight - (gameHeight / 3)), -(sam.getWidth()), (gameHeight - (gameHeight / 3)), -(sam.getWidth()), -(sam.getWidth()), 1, 1, sam.getRotation());

Answer

Use one of the batch.draw methods that has originX and originY parameters. originX and originY should be set to width/2 and height/2.

See methods here.

Leave a Reply

Your email address will not be published. Required fields are marked *