Animation Example - Libgdx Typing CST Test
Loading…
Animation Example — Libgdx Code
Plays a frame-based animation.
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class AnimationDemo extends ApplicationAdapter {
private SpriteBatch batch;
private Animation<TextureRegion> anim;
private float state;
@Override
public void create() {
batch = new SpriteBatch();
Texture sheet = new Texture("walk.png");
TextureRegion[][] frames = TextureRegion.split(sheet, 32, 32);
anim = new Animation<>(0.1f, frames[0]);
state = 0;
}
@Override
public void render() {
state += Gdx.graphics.getDeltaTime();
TextureRegion frame = anim.getKeyFrame(state, true);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(frame, 100, 100);
batch.end();
}
}Libgdx Language Guide
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.
Primary Use Cases
- ▸Cross-platform 2D and 3D games
- ▸Android-first game development
- ▸Custom in-house engines
- ▸Scientific/physics simulations
- ▸Desktop games with OpenGL rendering
Notable Features
- ▸Single Java/Kotlin codebase -> multiple platforms
- ▸Scene2D UI and Scene2D stage/actors
- ▸Built-in physics via Box2D
- ▸OpenGL-based rendering pipeline
- ▸Powerful math + linear algebra library
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.