I'm making a side-scroller game using LibGDX, where player can move only on X axis. The problem is that the player can only move on positive X value, so he can't go to negative X. This is not that big of a problem, but the main problem is that where-ever I choose his initial position, he will never move right, so he basically can't extend his initial X value. I'm making movement with Gdx.graphics.getDeltaTime(), but when I don't use it, strangely everything works right. Other things work alright, the animation change works, test outputs worked, the problem always occurs only in the part of adding delta time to the x axis.

Player's initial position:

private Actor hiro;
hiro = new Hiro("Hiro", 106, 4, 32, 32);

(I'm not using LibGDX's Actor class, I made my own which uses animations)

Player's constructor:

public Hiro(String name, int x, int y, int width, int height) {
    super(name, x, y, width, height);
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    standingRightTexture = new Texture("hiro_standing_right.png");
    standingLeftTexture = new Texture("hiro_standing_left.png");
    walkingRightTexture = new Texture("hiro_walking_right.png");
    walkingLeftTexture = new Texture("hiro_walking_left.png");
    standingRight = new Animation(standingRightTexture, 1, 10f, true);
    standingLeft = new Animation(standingLeftTexture, 1, 10f, true);
    walkingRight = new Animation(walkingRightTexture, 8, 0.6f, true);
    walkingLeft = new Animation(walkingLeftTexture, 8, 0.6f, true);
    state = State.STANDING_RIGHT;
    facingRight = true;

Player's movement:

        x += Gdx.graphics.getDeltaTime() * 6f;
        facingRight = true;
        state = State.WALKING_RIGHT;
        x -= Gdx.graphics.getDeltaTime() * 6f;
        facingRight = false;
        state = State.WALKING_LEFT;

Playing Screen's render method:

public void render(SpriteBatch spriteBatch) {
    spriteBatch.draw(hiro.getAnimation().getFrame(), hiro.getX(), hiro.getY());

If you want other segments of code, I'll provide it.

I greatly thank everyone whiling to help.

Edit: SOLVED! All I had to do was to use float axis instead of integer. Silly me!

  • \$\begingroup\$ Welcome to GDSE! Here, when we actual find an answer to a question, we actually write an answer and mark it as accepted instead of adding it to the post, and renaming the title to 'solved'. You can write an answer to your own question, and mark is as accepted, it's a perfectly acceptable behaviour here :) And in fact, it is what's expected! \$\endgroup\$
    – Vaillancourt
    Feb 17, 2017 at 18:25
  • \$\begingroup\$ Also, self-answering with a valid answer can make your post more interesting to read. :D This will prevent confusion from GDSE users whose looking for unanswered question as well. :) \$\endgroup\$ Feb 17, 2017 at 19:16

1 Answer 1


If you encounter a similar problem, be sure to always use float axis, not integer ones. When using integer, the game probably had problem with grounding the change of axis, since the Delta Time itself is float. Changing axis to float solved the problem perfectly.

  • \$\begingroup\$ Thanks for writing an answer :) Don't forget to come back in a couple of days to mark it as accepted :) \$\endgroup\$
    – Vaillancourt
    Feb 18, 2017 at 22:18

You must log in to answer this question.

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