I'm new to libgdx so please bear with me. I'm trying to create a 2D running game and have been trying to implement a scrolling background. So far I have been able to get the background to scroll but after a while it slows down and becomes choppy. Here is how I implemented it:
in my create method
bg = new Texture(Gdx.files.internal("bg1.png"));
bg.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
and in my render method i have
try {
sourceX += 15;
} catch (Exception e){
sourceX=0;
}
game.batch.draw(bg, 0, 0, sourceX, 0, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
This seems to work but after a while it becomes choppy. Any suggestions would be appreciated.
FPSLogger
, maybe you have a memory leak – MoirasourceX += 15
in a try block? that can't throw an exception – Moira