Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Moves a texture sprite using arrow keys.
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MoveSprite extends ApplicationAdapter {
private SpriteBatch batch;
private Texture img;
private float x = 100;
private float y = 100;
@Override
public void create() {
batch = new SpriteBatch();
img = new Texture("player.png");
}
@Override
public void render() {
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) x -= 2;
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) x += 2;
if (Gdx.input.isKeyPressed(Input.Keys.UP)) y += 2;
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) y -= 2;
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, x, y);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
img.dispose();
}
}LibGDX is a powerful, open-source Java game framework for building high-performance 2D and 3D games that run on desktop, Android, iOS, and web through a single shared codebase.
Origin & Creator
LibGDX was created by Mario Zechner and maintained by a global open-source community focused on flexible, high-performance Java game development.
Industrial Note
LibGDX thrives in Android game development, indie 2D/3D engines, simulation-heavy games, and education-especially for teams needing full control without being locked into heavy engines.