I've been struggling with a problem regarding rotations and relative positions between sprites (in this case, the sprites are just lines) - a bit off-topic, but should i be using the ShapeRenderer class to do this, though?

Anyway, it might be quite simple but i can't seem to figure it out properly. Heres a picture of the situation: https://gyazo.com/78988e07991fedc778eaeb70f8a04d8e

Now, after trying a bunch of different approaches, this piece of code is the one i'm testing right now:

` public class TestState extends AbstractGameState {

private static final String LINE = "lineEffect.png";

private Sprite[] sprites;

public TestState(GameStateManager 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

public void render(SpriteBatch batch) {
    for (Sprite sprite : sprites)

Any help on this would be appreciated, thanks in advance.

  • \$\begingroup\$ Returns the function "sprites[x].getX()" its corner X coordinate? If not, the origin should be set on it's corner point to get the correct rotation; \$\endgroup\$ Commented Nov 19, 2015 at 23:55
  • \$\begingroup\$ @AhmetZambak i'm not sure if that's what you're asking, but sprites[x].getX() returns 20, wich is the X value i applied in the line before. I thought that, by starting there, the X value wouldn't be moddified, just the sprite's rotation. \$\endgroup\$
    – Francisco
    Commented Nov 20, 2015 at 13:14

1 Answer 1


You should set the origin to a line edge:

// guess i might be messing up here
sprites[i].setOrigin(0, 0);

It depends on real line location in lineEffect.png.

  • \$\begingroup\$ thank you for the answer! Setting the origin to (0,0) was the solution. Thanks you very much! :) \$\endgroup\$
    – Francisco
    Commented Nov 24, 2015 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .