` public class TestState extends AbstractGameState {
private static final String LINE = "lineEffect.png";
private Sprite[] sprites;
public TestState(GameStateManager gsm) {
super(gsm);
sprites = new Sprite[2];
for (int i = 0; i < 2; i++) {
sprites[i] = new Sprite(new Texture(LINE));
// both lines starting at the same X and Y
sprites[i].setPosition(20, 50);
// both lines have the same size
sprites[i].setSize(100, 2);
// guess i might be messing up here
sprites[i].setOrigin(sprites[i].getX(), sprites[i].getY());
}
// for testing purposes
sprites[0].setRotation(-20);
sprites[1].setRotation(45);
}
@Override
public void render(SpriteBatch batch) {
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Sprite sprite : sprites)
sprite.draw(batch);
batch.end();
}`
LibGDX - Rotating sprites from their corners.
The origin is relative to the sprite's upper-left corner. So, if you want rotations around the upper-left corner, the origin should be 0,0. If you want rotations around the sprite's center, you would use width/2,height/2 (or use setOriginCenter). Note that the origin is also used as an offset to the sprite's position. Essentially, the origin is subtracted from the position when drawing.
The origin is relative to the sprite's upper-left corner. So, if you want rotations around the upper-left corner, the origin should be 0,0. If you want rotations around the sprite's center, you would use width/2,height/2 (or use setOriginCenter). Note that the origin is also used as an offset to the sprite's position. Essentially, the origin is subtracted from the position when drawing.
Fixed by seting the origin to (0, 0), thank you so much!
The origin is relative to the sprite's upper-left corner. So, if you want rotations around the upper-left corner, the origin should be 0,0. If you want rotations around the sprite's center, you would use width/2,height/2 (or use setOriginCenter). Note that the origin is also used as an offset to the sprite's position. Essentially, the origin is subtracted from the position when drawing.
The origin is relative to bottom left in libgdx.