My player sprite glitches when it moves across the screen. I've tried multiplying movements by delta time. I've tried rounding. It seems to do this completely at random. Sometimes I can move it all the way across the screen and its fine, other times it glitches and twitches the entire way.
@Override
public void render(float delta) {
//update the camera
camera.update();
//clear the screen with black
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//update the renderer and render
renderer.setView(camera);
renderer.render();
//update players movement on x-axis and apply gravity and increase x-axis speed if the player is jumping
if(player.movingLeft)
player.movement[0] -= Math.round(player.playerSpeed * delta);
if(player.movingRight)
player.movement[0] += Math.round(player.playerSpeed * delta);
if(player.movingUp)
player.movement[1] += player.playerSpeed * delta;
//handle jumping
if(player.isJumping) {
if(player.jumpCurrentY < player.MAX_JUMP_DURATION) {
player.momentum = 0;
player.jumpSpeed++;
player.movement[1] = player.jumpSpeed;
if (player.jumpSpeed > 5)
player.jumpSpeed = 5;
player.jumpCurrentY++;
} else if(player.hangTime < player.MAX_HANG_TIME) {
player.momentum = 0;
player.hangTime++;
player.movement[1] = 2.8f;
} else {
player.isJumping = false;
player.jumpCurrentY = 0;
player.hangTime = 0;
player.jumpSpeed = 0;
player.momentum = gravity;
}
} else {
player.jumpCurrentY = 0;
}
updateSprite(delta, player, player.movement, collidableTiles);
//set sprite batch projection matrix and draw to the screen
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
player.draw(game.batch);
game.batch.end();
//reset player movement
Arrays.fill(player.movement, 0);
//increment player momentum by gravity and assign it to the players y-axis movement
player.momentum += gravity;
player.movement[1] = player.momentum;
player.momentum += -1;
if(player.momentum < -5)
player.momentum = -5;
//TEMPORARY
camera.position.set(Math.round(player.getX()), Math.round(player.getY()), 0);
}