mcfly soft
mcfly soft

Reputation: 11665

Howto rotate a Sprite after resizing the Sprite with setBounds ? (LIBGDX)

I have a Bitmap (png) loaded into my Sprite with a specific size (200) and a Center at 100/100 for rotation:

Sprite round = loadSprite(200,200);
round.setPosition(x,y)

When Rotating round.setRotation() the Sprite rotates around the correct Center.

Now I would like to size the Sprite to a new Size (400,400) and still want to rotate around the Center (200/200):

round.setBounds(x,y,400,400)
rount.setCenter(200,200);

When rotating again, it is still rotating around the old Center 100/100.

How to do this corectly ?

Upvotes: 0

Views: 130

Answers (1)

Morchul
Morchul

Reputation: 2037

setCenter(x, y) set the position of the Sprite so it is centered to this position:

/** Sets the position so that the sprite is centered on (x, y) */
public void setCenter(float x, float y){
    ...
}

You need the function setOrigin(originX, originY):

/** Sets the origin in relation to the sprite's position for scaling and rotation. */
public void setOrigin (float originX, float originY) {
    ...
}

Upvotes: 1

Related Questions