CoolMAn
CoolMAn

Reputation: 1861

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

Upvotes: 0

Views: 527

Answers (1)

Tenfour04
Tenfour04

Reputation: 93581

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.

Upvotes: 1

Related Questions