user8277208
user8277208

Reputation: 13

How to rotate a Sprite around the circle in LibGDX?

I want to rota a sprite around a circle, but I couldn't do that. If I could not tell my problem you can understand from this picture:

square rotating around circle

Upvotes: 0

Views: 390

Answers (1)

Arctic45
Arctic45

Reputation: 1098

Sprite has a method setOrigin(), https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setOrigin-float-float-

Set Sprite's origin at the center of your circle and rotate it. Code will look similar to this:

float circleCenterX = ...;
float circleCenterY = ...;
float angle = ...;
Sprite sprite = ...;

sprite.setOrigin(circleCenterX, circleCenterY);
sprite.rotate(angle); // or sprite.setRotation(angle);

Upvotes: 2

Related Questions