I'm making a game in LibGDX. I have 4 textures as a parallax background and some obstacles (one in the upper part and others in the bottom part of the screen), this is the movement part:
//Parallax
if (bckgndmiddle_x <= -Const.VIEWPORT_W*2+(game_speed*delta)/2) bckgndmiddle_x=-(game_speed*delta)/2; else bckgndmiddle_x-=(game_speed*delta)/2;
if (bckgndfar_x <= -Const.VIEWPORT_W*2+(game_speed*delta)/5) bckgndfar_x=-(game_speed*delta)/5; else bckgndfar_x-=(game_speed*delta)/5;
for (Obstacle obst:obstacles) {
obst.update(game_speed*delta);
}
//End Main game loop
player.update();
game.batch.begin();
game.batch.draw(wall, bckgndfar_x,floor.getRegionHeight()+100);
game.batch.draw(wall, bckgndfar_x+wall.getRegionWidth(),floor.getRegionHeight()+100);
game.batch.draw(bot_furniture, bckgndmiddle_x,floor.getRegionHeight());
game.batch.draw(bot_furniture, bckgndmiddle_x+bot_furniture.getRegionWidth(),floor.getRegionHeight());
game.batch.draw(floor, bckgndmiddle_x,0);
game.batch.draw(floor, bckgndmiddle_x+floor.getRegionWidth(),0);
game.batch.draw(ceiling, bckgndfar_x,Const.VIEWPORT_H-ceiling.getRegionHeight());
game.batch.draw(ceiling, bckgndfar_x+ceiling.getRegionWidth(),Const.VIEWPORT_H-ceiling.getRegionHeight());
The obstacle update method is just x-= speed; as speed is the parameter received
The problem is that from time to time the textures wiggles strange, like if the device cannot handle the game and freezes for a split second.
Any clue why is this happening?
EDIT
What happens is that the textures stutters from time to time (I'm Spanish and I didn't know that word)
I think that it must be something related to the second image of each part of the background, that adding of the width. Like it adds the width, but sometimes it is too much because of a drop of fps (like 1 or 2 fps) and the next time it "moves" back to the good position because fps are back to normal.
EDIT 2 I tried it without the obstacles and it still stutters, I tried it again with the obstacles and without the background and it doesnt, so it must be something with what I said in the first edit.
BTW, the FPS drop is less than 1 (checked)
I have just tried to draw a entire background image (no parallax) and still the same issue.