Try Live
Add Docs
Rankings
Pricing
Enterprise
Docs
Install
Theme
Install
Docs
Pricing
Enterprise
More...
More...
Try Live
Rankings
Create API Key
Add Docs
libGDX
https://github.com/libgdx/libgdx
Admin
Desktop/Android/HTML5/iOS Java game development framework
Tokens:
17,022
Snippets:
91
Trust Score:
7.3
Update:
2 weeks ago
Context
Skills
Chat
Benchmark
72.9
Suggestions
Latest
Show doc for...
Code
Info
Show Results
Context Summary (auto-generated)
Raw
Copy
Link
# libGDX - Cross-Platform Game Development Framework libGDX is a free, open-source game development framework written in Java that enables cross-platform development for Desktop (Windows, Linux, macOS), Android, iOS, and Web (HTML5/WebGL). The framework provides a unified API for graphics rendering via OpenGL ES, audio playback and recording, input handling (keyboard, mouse, touch, accelerometer), file I/O, and networking. libGDX follows an event-driven architecture centered around the `ApplicationListener` interface, which manages the complete application lifecycle including creation, rendering, pausing, resuming, and disposal. The core of libGDX is organized around the `Gdx` class, which provides static access to essential subsystems: `Gdx.graphics` for rendering and display management, `Gdx.audio` for sound and music, `Gdx.input` for user interaction, `Gdx.files` for file system access, and `Gdx.net` for networking. This design enables developers to write platform-agnostic code that works seamlessly across all supported platforms while still allowing platform-specific customization when needed. --- ## ApplicationListener - Core Application Lifecycle The `ApplicationListener` interface defines the complete lifecycle of a libGDX application. Implement this interface to receive callbacks when the application is created, rendered, resized, paused, resumed, and destroyed. All methods are called on a thread with an active OpenGL context. ```java import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.Texture; public class MyGame implements ApplicationListener { private SpriteBatch batch; private Texture texture; @Override public void create() { // Called once when the application starts batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("player.png")); } @Override public void render() { // Called every frame - clear screen and draw Gdx.gl.glClearColor(0.15f, 0.15f, 0.2f, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 100, 100); batch.end(); } @Override public void resize(int width, int height) { // Called when the window is resized } @Override public void pause() { // Called when the application loses focus (e.g., incoming call on Android) } @Override public void resume() { // Called when the application regains focus } @Override public void dispose() { // Called when the application is destroyed - clean up resources batch.dispose(); texture.dispose(); } } ``` --- ## Game and Screen - Multi-Screen Applications The `Game` class extends `ApplicationListener` and delegates rendering to `Screen` objects, enabling easy multi-screen applications (menu screens, game screens, settings screens). Screens are not disposed automatically - manage screen lifecycle explicitly. ```java import com.badlogic.gdx.Game; import com.badlogic.gdx.Screen; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; // Main game class public class MyGame extends Game { public SpriteBatch batch; @Override public void create() { batch = new SpriteBatch(); setScreen(new MainMenuScreen(this)); } @Override public void dispose() { batch.dispose(); if (getScreen() != null) getScreen().dispose(); } } // A game screen public class MainMenuScreen implements Screen { private final MyGame game; public MainMenuScreen(MyGame game) { this.game = game; } @Override public void show() { // Called when this screen becomes the current screen } @Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (Gdx.input.isTouched()) { game.setScreen(new GameScreen(game)); // Switch to game screen dispose(); // Dispose this screen } } @Override public void resize(int width, int height) {} @Override public void pause() {} @Override public void resume() {} @Override public void hide() {} @Override public void dispose() {} } ``` --- ## SpriteBatch and Texture - 2D Rendering `SpriteBatch` efficiently batches draw calls for 2D sprites using OpenGL. `Texture` represents an image loaded into GPU memory. Always dispose textures and batches when done to avoid memory leaks. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; public class RenderingExample { private SpriteBatch batch; private Texture texture; private TextureRegion region; public void create() { batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("spritesheet.png")); // Create a region from part of the texture (x, y, width, height) region = new TextureRegion(texture, 0, 0, 64, 64); } public void render() { batch.begin(); // Draw texture at position (100, 100) batch.draw(texture, 100, 100); // Draw with size batch.draw(texture, 200, 100, 128, 128); // Draw texture region batch.draw(region, 300, 100); // Draw with rotation and scaling batch.draw(region, 400, 100, // x, y position 32, 32, // origin x, y (for rotation) 64, 64, // width, height 1.5f, 1.5f, // scale x, y 45f); // rotation in degrees batch.end(); } public void dispose() { batch.dispose(); texture.dispose(); } } ``` --- ## Sprite - Position, Rotation, and Scaling `Sprite` combines a `TextureRegion` with geometry information (position, size, origin, rotation, scale, color). It simplifies drawing transformed sprites and tracks dirty state for efficient vertex updates. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class SpriteExample { private SpriteBatch batch; private Sprite sprite; private float rotation = 0; public void create() { batch = new SpriteBatch(); Texture texture = new Texture(Gdx.files.internal("character.png")); sprite = new Sprite(texture); sprite.setPosition(100, 100); sprite.setSize(64, 64); sprite.setOriginCenter(); // Set rotation/scale origin to center } public void render(float delta) { // Update sprite rotation += 90 * delta; // Rotate 90 degrees per second sprite.setRotation(rotation); sprite.setScale(1.0f + 0.5f * (float)Math.sin(rotation * 0.1f)); // Move sprite if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { sprite.translateX(200 * delta); } // Draw sprite batch.begin(); sprite.draw(batch); batch.end(); } public void dispose() { batch.dispose(); sprite.getTexture().dispose(); } } ``` --- ## TextureAtlas - Sprite Sheet Management `TextureAtlas` loads sprite sheets created by TexturePacker, managing multiple texture regions in a single texture for better batching performance. Regions are accessed by name. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.utils.Array; public class TextureAtlasExample { private SpriteBatch batch; private TextureAtlas atlas; private AtlasRegion playerStand; private Animation<AtlasRegion> walkAnimation; private float stateTime = 0; public void create() { batch = new SpriteBatch(); atlas = new TextureAtlas(Gdx.files.internal("game.atlas")); // Get single region by name playerStand = atlas.findRegion("player_stand"); // Get multiple regions for animation (player_walk_1, player_walk_2, etc.) Array<AtlasRegion> walkFrames = atlas.findRegions("player_walk"); walkAnimation = new Animation<>(0.1f, walkFrames, Animation.PlayMode.LOOP); } public void render(float delta) { stateTime += delta; batch.begin(); // Draw static region batch.draw(playerStand, 100, 100); // Draw animated region AtlasRegion currentFrame = walkAnimation.getKeyFrame(stateTime); batch.draw(currentFrame, 200, 100); batch.end(); } public void dispose() { batch.dispose(); atlas.dispose(); // Disposes all textures in the atlas } } ``` --- ## Animation - Frame-Based Animation `Animation<T>` manages a sequence of key frames with configurable frame duration and play modes (NORMAL, LOOP, LOOP_PINGPONG, LOOP_REVERSED, LOOP_RANDOM). Track elapsed time externally. ```java import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class AnimationExample { private Animation<TextureRegion> runAnimation; private float stateTime = 0; private SpriteBatch batch; public void create() { batch = new SpriteBatch(); // Load sprite sheet and split into frames Texture sheet = new Texture("run_animation.png"); TextureRegion[][] tmp = TextureRegion.split(sheet, 64, 64); // 64x64 frames // Flatten 2D array to 1D TextureRegion[] frames = new TextureRegion[8]; for (int i = 0; i < 8; i++) { frames[i] = tmp[0][i]; // First row, 8 columns } // Create animation: 0.1 seconds per frame, looping runAnimation = new Animation<>(0.1f, frames); runAnimation.setPlayMode(Animation.PlayMode.LOOP); } public void render(float delta) { stateTime += delta; // Get current frame based on state time TextureRegion currentFrame = runAnimation.getKeyFrame(stateTime); // Check if animation finished (for non-looping animations) boolean finished = runAnimation.isAnimationFinished(stateTime); batch.begin(); batch.draw(currentFrame, 100, 100); batch.end(); } } ``` --- ## OrthographicCamera - 2D Camera Control `OrthographicCamera` provides a 2D orthographic view for rendering. Control the visible area, position, zoom, and use it to convert between screen and world coordinates. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; public class CameraExample { private OrthographicCamera camera; private SpriteBatch batch; private Vector3 touchPos = new Vector3(); public void create() { // Create camera with viewport size camera = new OrthographicCamera(); camera.setToOrtho(false, 800, 480); // false = y-up coordinate system batch = new SpriteBatch(); } public void render(float delta) { // Update camera position (follow player) camera.position.x = playerX; camera.position.y = playerY; camera.update(); // Must call after changes // Zoom control if (Gdx.input.isKeyPressed(Input.Keys.Z)) { camera.zoom += 0.02f; } if (Gdx.input.isKeyPressed(Input.Keys.X)) { camera.zoom -= 0.02f; } camera.zoom = Math.max(0.1f, Math.min(camera.zoom, 2f)); // Clamp zoom // Convert screen coordinates to world coordinates if (Gdx.input.isTouched()) { touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(touchPos); // Now touchPos contains world coordinates } // Apply camera to batch batch.setProjectionMatrix(camera.combined); batch.begin(); // Draw game objects... batch.end(); } public void resize(int width, int height) { camera.viewportWidth = width; camera.viewportHeight = height; camera.update(); } } ``` --- ## Input Handling - Keyboard, Mouse, Touch The `Input` interface provides polling methods for keyboard, mouse, and touch input. For event-based input, implement `InputProcessor` and register it with `Gdx.input.setInputProcessor()`. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputProcessor; public class InputExample { public void setupInputProcessor() { Gdx.input.setInputProcessor(new InputAdapter() { @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.SPACE) { player.jump(); return true; } return false; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { if (button == Input.Buttons.LEFT) { handleClick(screenX, screenY); return true; } return false; } @Override public boolean scrolled(float amountX, float amountY) { camera.zoom += amountY * 0.1f; return true; } }); } public void render(float delta) { // Polling-based input (check every frame) float speed = 200 * delta; if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A)) { playerX -= speed; } if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.isKeyPressed(Input.Keys.D)) { playerX += speed; } // Check for just-pressed (true only on first frame) if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { showPauseMenu(); } // Touch/mouse position if (Gdx.input.isTouched()) { int x = Gdx.input.getX(); int y = Gdx.input.getY(); int deltaX = Gdx.input.getDeltaX(); int deltaY = Gdx.input.getDeltaY(); } // Multi-touch support for (int i = 0; i < 10; i++) { if (Gdx.input.isTouched(i)) { int touchX = Gdx.input.getX(i); int touchY = Gdx.input.getY(i); } } } } ``` --- ## Audio - Sound Effects and Music `Sound` loads short audio clips into memory for low-latency playback (sound effects). `Music` streams audio from disk for longer tracks (background music). Both support volume, panning, pitch, and looping. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.audio.Music; public class AudioExample { private Sound jumpSound; private Sound explosionSound; private Music backgroundMusic; private long lastExplosionId; public void create() { // Load sound effects (fully loaded into memory) jumpSound = Gdx.audio.newSound(Gdx.files.internal("jump.wav")); explosionSound = Gdx.audio.newSound(Gdx.files.internal("explosion.ogg")); // Load music (streamed from disk) backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("background.mp3")); backgroundMusic.setLooping(true); backgroundMusic.setVolume(0.5f); backgroundMusic.play(); } public void playJump() { jumpSound.play(1.0f); // Play at full volume } public void playExplosion(float pan) { // Play with volume, pitch, and panning // Returns sound ID for later control lastExplosionId = explosionSound.play(0.8f, 1.2f, pan); } public void stopLastExplosion() { explosionSound.stop(lastExplosionId); } public void toggleMusic() { if (backgroundMusic.isPlaying()) { backgroundMusic.pause(); } else { backgroundMusic.play(); } } public void setMusicPosition(float seconds) { backgroundMusic.setPosition(seconds); } public void dispose() { jumpSound.dispose(); explosionSound.dispose(); backgroundMusic.dispose(); } } ``` --- ## Files - Cross-Platform File Access The `Files` interface provides consistent file access across platforms. Use `FileType.Internal` for bundled assets, `FileType.External` for user data, and `FileType.Local` for application data. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; public class FileExample { public void readWriteFiles() { // Internal files (read-only, bundled with app) FileHandle internalFile = Gdx.files.internal("data/levels.json"); String jsonContent = internalFile.readString(); // External files (user's home directory / SD card) FileHandle saveFile = Gdx.files.external("mygame/save.dat"); if (saveFile.exists()) { byte[] saveData = saveFile.readBytes(); } // Local files (app's private directory) FileHandle configFile = Gdx.files.local("config.txt"); configFile.writeString("volume=0.8\nfullscreen=true", false); // List directory contents FileHandle levelDir = Gdx.files.internal("levels"); for (FileHandle level : levelDir.list()) { String levelName = level.nameWithoutExtension(); } // Check file properties boolean exists = internalFile.exists(); boolean isDirectory = internalFile.isDirectory(); long lastModified = internalFile.lastModified(); long length = internalFile.length(); String extension = internalFile.extension(); } } ``` --- ## Scene2D - UI Framework Scene2D provides a 2D scene graph with hierarchical actors, event handling, and actions. `Stage` manages the scene and input, while UI widgets like `Table`, `Button`, `Label` create interfaces. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.utils.viewport.ScreenViewport; public class Scene2DExample { private Stage stage; private Skin skin; public void create() { stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage); // Load UI skin (defines styles for widgets) skin = new Skin(Gdx.files.internal("uiskin.json")); // Create table for layout Table table = new Table(); table.setFillParent(true); stage.addActor(table); // Add widgets Label titleLabel = new Label("My Game", skin); TextButton playButton = new TextButton("Play", skin); TextButton optionsButton = new TextButton("Options", skin); Slider volumeSlider = new Slider(0, 1, 0.1f, false, skin); // Layout with table table.add(titleLabel).colspan(2).padBottom(50); table.row(); table.add(playButton).width(200).height(50).pad(10); table.row(); table.add(optionsButton).width(200).height(50).pad(10); table.row(); table.add(new Label("Volume:", skin)); table.add(volumeSlider).width(200); // Add click listener playButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { startGame(); } }); // Add value change listener volumeSlider.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { float volume = volumeSlider.getValue(); setVolume(volume); } }); } public void render() { stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); } public void resize(int width, int height) { stage.getViewport().update(width, height, true); } public void dispose() { stage.dispose(); skin.dispose(); } } ``` --- ## AssetManager - Asynchronous Asset Loading `AssetManager` loads assets asynchronously, preventing load time freezes. It manages dependencies, reference counting, and provides progress feedback for loading screens. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.audio.Music; public class AssetManagerExample { private AssetManager manager; private boolean assetsLoaded = false; public void create() { manager = new AssetManager(); // Queue assets for loading manager.load("player.png", Texture.class); manager.load("enemies.atlas", TextureAtlas.class); manager.load("explosion.wav", Sound.class); manager.load("background.mp3", Music.class); } public void render() { if (!assetsLoaded) { // Continue loading (returns true when complete) if (manager.update()) { assetsLoaded = true; onAssetsLoaded(); } // Display loading progress float progress = manager.getProgress(); // 0.0 to 1.0 drawLoadingBar(progress); } else { // Game rendering renderGame(); } } private void onAssetsLoaded() { // Retrieve loaded assets Texture playerTexture = manager.get("player.png", Texture.class); TextureAtlas enemyAtlas = manager.get("enemies.atlas", TextureAtlas.class); Sound explosionSound = manager.get("explosion.wav", Sound.class); Music backgroundMusic = manager.get("background.mp3", Music.class); } public void unloadLevel() { // Unload specific assets manager.unload("enemies.atlas"); } public void dispose() { manager.dispose(); // Disposes all loaded assets } } ``` --- ## Vector2 and Math Utilities `Vector2` provides 2D vector operations with method chaining. `MathUtils` offers trigonometry, random numbers, clamping, and interpolation utilities optimized for game development. ```java import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Interpolation; public class MathExample { private Vector2 position = new Vector2(); private Vector2 velocity = new Vector2(); private Vector2 target = new Vector2(); public void update(float delta) { // Vector operations (method chaining) velocity.set(100, 50) .nor() // Normalize to unit vector .scl(200); // Scale to speed 200 position.add(velocity.x * delta, velocity.y * delta); // Calculate direction to target Vector2 direction = target.cpy().sub(position).nor(); float distance = position.dst(target); float angle = direction.angleDeg(); // Angle in degrees // Lerp (linear interpolation) towards target position.lerp(target, 0.1f); // MathUtils examples float randomX = MathUtils.random(0f, 800f); int randomInt = MathUtils.random(1, 100); boolean chance = MathUtils.randomBoolean(0.3f); // 30% chance // Clamping values float health = MathUtils.clamp(health, 0, 100); // Trigonometry (uses radians, but has degree methods) float sinValue = MathUtils.sinDeg(45); float cosValue = MathUtils.cosDeg(45); // Interpolation for smooth animations float t = 0.5f; // Progress 0-1 float smoothed = Interpolation.smooth.apply(t); float bounced = Interpolation.bounceOut.apply(t); float elastic = Interpolation.elasticOut.apply(t); } } ``` --- ## HTTP Networking The `Net` interface provides cross-platform HTTP request functionality. Requests are asynchronous and responses are delivered via callbacks on a worker thread. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Net; import com.badlogic.gdx.net.HttpParametersUtils; import com.badlogic.gdx.net.HttpStatus; public class NetworkExample { public void sendGetRequest() { Net.HttpRequest request = new Net.HttpRequest(Net.HttpMethods.GET); request.setUrl("https://api.example.com/scores"); request.setTimeOut(5000); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { HttpStatus status = httpResponse.getStatus(); if (status.getStatusCode() == 200) { String response = httpResponse.getResultAsString(); // Parse JSON response on main thread Gdx.app.postRunnable(() -> parseScores(response)); } } @Override public void failed(Throwable t) { Gdx.app.error("Network", "Request failed", t); } @Override public void cancelled() { Gdx.app.log("Network", "Request cancelled"); } }); } public void sendPostRequest(String username, int score) { Net.HttpRequest request = new Net.HttpRequest(Net.HttpMethods.POST); request.setUrl("https://api.example.com/submit"); request.setHeader("Content-Type", "application/x-www-form-urlencoded"); java.util.Map<String, String> params = new java.util.HashMap<>(); params.put("username", username); params.put("score", String.valueOf(score)); request.setContent(HttpParametersUtils.convertHttpParameters(params)); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { // Handle response } @Override public void failed(Throwable t) {} @Override public void cancelled() {} }); } public void openWebsite() { Gdx.net.openURI("https://libgdx.com"); } } ``` --- ## Graphics Utilities The `Graphics` interface provides display management, frame timing, and OpenGL context information. Use it for delta time, FPS, display modes, and vsync control. ```java import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Graphics; public class GraphicsExample { public void displayInfo() { // Frame timing float deltaTime = Gdx.graphics.getDeltaTime(); // Seconds since last frame int fps = Gdx.graphics.getFramesPerSecond(); long frameId = Gdx.graphics.getFrameId(); // Screen dimensions int width = Gdx.graphics.getWidth(); int height = Gdx.graphics.getHeight(); int backBufferWidth = Gdx.graphics.getBackBufferWidth(); // For HDPI int backBufferHeight = Gdx.graphics.getBackBufferHeight(); // Display density (useful for UI scaling) float density = Gdx.graphics.getDensity(); float ppiX = Gdx.graphics.getPpiX(); float ppiY = Gdx.graphics.getPpiY(); // Check OpenGL capabilities boolean gl30 = Gdx.graphics.isGL30Available(); boolean gl31 = Gdx.graphics.isGL31Available(); } public void displayModes() { // Get available display modes Graphics.DisplayMode[] modes = Gdx.graphics.getDisplayModes(); for (Graphics.DisplayMode mode : modes) { System.out.println(mode.width + "x" + mode.height + " @ " + mode.refreshRate + "Hz"); } // Set fullscreen Graphics.DisplayMode desktopMode = Gdx.graphics.getDisplayMode(); Gdx.graphics.setFullscreenMode(desktopMode); // Set windowed mode Gdx.graphics.setWindowedMode(1280, 720); // VSync and frame rate Gdx.graphics.setVSync(true); Gdx.graphics.setForegroundFPS(60); // Window properties (desktop only) Gdx.graphics.setTitle("My Game"); Gdx.graphics.setResizable(true); } } ``` --- libGDX is designed for both rapid prototyping and production-quality games, supporting everything from simple 2D mobile games to complex 3D simulations. The framework excels at cross-platform development where a single codebase targets multiple platforms without modification. Common use cases include 2D platformers, RPGs, puzzle games, and casual mobile games that benefit from the efficient SpriteBatch rendering and Scene2D UI system. For larger projects, libGDX integrates well with popular tools: TexturePacker for sprite atlases, Tiled for level design, Hiero for bitmap fonts, and Box2D for physics (available as an extension). The AssetManager enables sophisticated loading screens and memory management for games with large asset bases. The framework's modular architecture allows developers to use only what they need while extending functionality through community-maintained extensions for controllers, AI, particle effects, and more.