This code makes image flicker while moving left,right,down or up.
public class MoveSpriteExample extends GdxTest implements InputProcessor {
Texture texture;
SpriteBatch batch;
OrthographicCamera camera;
Vector3 spritePosition = new Vector3();
Sprite sprite;
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
batch = new SpriteBatch();
camera = new OrthographicCamera();
camera.setToOrtho(false, w, h);
texture = new Texture(Gdx.files.internal("data/TestImg.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite = new Sprite(texture);
sprite.setSize(32, 32);
spritePosition.y=100;
sprite.setPosition(spritePosition.x,spritePosition.x);
}
public void render() {
// set the clear color and clear the screen.
Gdx.gl.glClearColor(1,1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
// camera.apply(Gdx.gl10);
sprite.setPosition(spritePosition.x,spritePosition.y);
batch.begin();
sprite.draw(batch);
batch.end();
if (Gdx.input.isKeyPressed(Keys.D)==true)
{
spritePosition.x += 2;
}else if (Gdx.input.isKeyPressed( Keys.A)==true)
{
spritePosition.x -= 2;
}
else if (Gdx.input.isKeyPressed( Keys.Z)==true)
{
spritePosition.y -= 2;
}
else if (Gdx.input.isKeyPressed( Keys.W)==true)
{
spritePosition.y += 2;
}
// camera.unproject(spritePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0));
// if a finger is down, set the sprite's x/y coordinate.
}
}