Top Related Projects
Godot Engine – Multi-platform 2D and 3D game engine
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
Simple and Fast Multimedia Library
FNA - Accuracy-focused XNA4 reimplementation for open platforms
One framework for creating powerful cross-platform games.
Quick Overview
LibGDX is a cross-platform Java game development framework. It provides a robust set of tools and APIs for creating games and applications that can run on desktop, Android, iOS, and web platforms. LibGDX aims to simplify game development while offering powerful features and performance optimizations.
Pros
- Cross-platform compatibility (desktop, mobile, and web)
- Extensive documentation and active community support
- High performance and low-level access to hardware
- Rich set of built-in tools and utilities for game development
Cons
- Steeper learning curve compared to some other game engines
- Limited visual editor support (primarily code-based development)
- iOS deployment requires additional setup and tools
- May be overkill for simple 2D games or applications
Code Examples
- Creating a basic game screen:
public class GameScreen implements Screen {
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
// Other Screen methods...
}
- Loading and rendering a texture:
public class TextureExample extends ApplicationAdapter {
private SpriteBatch batch;
private Texture texture;
@Override
public void create() {
batch = new SpriteBatch();
texture = new Texture("image.png");
}
@Override
public void render() {
batch.begin();
batch.draw(texture, 0, 0);
batch.end();
}
}
- Handling user input:
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
player.moveLeft();
} else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
player.moveRight();
}
if (Gdx.input.justTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
player.setPosition(touchPos.x, touchPos.y);
}
Getting Started
- Add LibGDX dependency to your project (e.g., using Gradle):
dependencies {
implementation 'com.badlogicgames.gdx:gdx:1.11.0'
implementation 'com.badlogicgames.gdx:gdx-backend-lwjgl3:1.11.0'
implementation 'com.badlogicgames.gdx:gdx-platform:1.11.0:natives-desktop'
}
- Create a main class that extends
Game
:
import com.badlogic.gdx.Game;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
public class MyGame extends Game {
@Override
public void create() {
setScreen(new GameScreen());
}
public static void main(String[] args) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setTitle("My LibGDX Game");
config.setWindowedMode(800, 600);
new Lwjgl3Application(new MyGame(), config);
}
}
- Implement your game logic in the
GameScreen
class (as shown in the code examples).
Competitor Comparisons
Godot Engine – Multi-platform 2D and 3D game engine
Pros of Godot
- Complete game engine with built-in editor and visual scripting
- Supports 2D and 3D game development out of the box
- Free and open-source with a more permissive MIT license
Cons of Godot
- Steeper learning curve for beginners compared to LibGDX
- Smaller community and ecosystem than LibGDX
- Less flexible for low-level customization
Code Comparison
Godot (GDScript):
extends Sprite2D
func _ready():
position = Vector2(100, 100)
scale = Vector2(2, 2)
LibGDX (Java):
public class MyActor extends Actor {
public MyActor() {
setPosition(100, 100);
setScale(2, 2);
}
}
Both examples demonstrate setting position and scale for a sprite or actor, showcasing the syntax differences between GDScript and Java. Godot's approach is more concise, while LibGDX offers more familiar Java syntax.
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
Pros of cocos2d-x
- Better performance for complex 2D games, especially on mobile devices
- More extensive built-in tools and editors for game development
- Stronger support for 3D graphics and effects
Cons of cocos2d-x
- Steeper learning curve, especially for developers new to C++
- Less flexible and modular architecture compared to libGDX
- Smaller community and fewer third-party extensions
Code Comparison
cocos2d-x (C++):
auto sprite = Sprite::create("player.png");
sprite->setPosition(Vec2(100, 100));
this->addChild(sprite);
libGDX (Java):
Texture texture = new Texture("player.png");
Sprite sprite = new Sprite(texture);
sprite.setPosition(100, 100);
stage.addActor(sprite);
Both frameworks provide similar functionality for creating and positioning sprites, but cocos2d-x uses C++ syntax and its own Vec2 class, while libGDX uses Java and separate Texture and Sprite classes.
Simple and Fast Multimedia Library
Pros of SFML
- Native C++ library, offering better performance for desktop applications
- Simpler and more lightweight, easier to learn for beginners
- More flexible for low-level control and custom rendering
Cons of SFML
- Limited to desktop platforms (Windows, macOS, Linux)
- Smaller community and ecosystem compared to LibGDX
- Less comprehensive feature set, requiring more manual implementation
Code Comparison
SFML (C++):
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
while (window.isOpen()) {
// Game loop
}
return 0;
}
LibGDX (Java):
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
public class MyGame extends ApplicationAdapter {
@Override
public void create() {
// Initialization
}
@Override
public void render() {
// Game loop
}
}
SFML provides a more direct approach to window creation and game loop management, while LibGDX abstracts these details through its application lifecycle methods. SFML's code is more explicit, giving developers greater control over the application structure, whereas LibGDX offers a more streamlined and cross-platform compatible approach.
FNA - Accuracy-focused XNA4 reimplementation for open platforms
Pros of FNA
- Closer to XNA API, easier migration for XNA developers
- Better performance for games targeting desktop platforms
- Smaller codebase, potentially easier to understand and modify
Cons of FNA
- Limited platform support compared to LibGDX
- Smaller community and ecosystem
- Less frequent updates and maintenance
Code Comparison
FNA (C#):
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(texture, position, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
LibGDX (Java):
@Override
public void render() {
Gdx.gl.glClearColor(0.39f, 0.58f, 0.93f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texture, position.x, position.y);
batch.end();
}
Both frameworks provide similar functionality for rendering sprites, but FNA's syntax is closer to XNA, while LibGDX uses a more Java-centric approach. FNA's performance may be slightly better for desktop platforms, but LibGDX offers broader platform support and a larger ecosystem.
One framework for creating powerful cross-platform games.
Pros of MonoGame
- C# language, which is more familiar to many developers and integrates well with Visual Studio
- Better support for console development (Xbox, PlayStation)
- Closer to XNA framework, making it easier for XNA developers to transition
Cons of MonoGame
- Smaller community and ecosystem compared to LibGDX
- Less comprehensive documentation and tutorials
- More limited cross-platform support, especially for mobile platforms
Code Comparison
MonoGame:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(texture, position, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
LibGDX:
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texture, position.x, position.y);
batch.end();
}
Both frameworks offer similar functionality for game development, but MonoGame is more suited for C# developers and console targets, while LibGDX provides better cross-platform support and a larger community, especially for mobile and desktop development.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Cross-platform Game Development Framework
libGDX is a cross-platform Java game development framework based on OpenGL (ES), designed for Windows, Linux, macOS, Android, web browsers, and iOS. It provides a robust and well-established environment for rapid prototyping and iterative development. Unlike other frameworks, libGDX does not impose a specific design or coding style, allowing you the freedom to create games according to your preferences.
Open Source, Feature Packed, and Fostering a Large Third-Party Ecosystem
libGDX is released under the Apache 2.0 License, offering unrestricted usage in both commercial and non-commercial projects. While not mandatory, we appreciate any credit given to libGDX when you release a game or app using it. Check out our showcase for a selection of popular libGDX-powered games. With libGDX, you gain access to a comprehensive set of tools and features to develop multi-platform 2D and 3D games using Java.
Moreover, libGDX boasts a vibrant third-party ecosystem, with numerous tools and libraries that streamline development tasks. Explore the awesome-libgdx repository for a curated list of libGDX-centered libraries, serving as an excellent starting point for newcomers in the libGDX community.
An example game created with libGDX: Pathway by Robotality. Discover more captivating games in our Showcase.
Getting Started with libGDX / Documentation
Thanks to Gradle, you can easily set up libGDX without the need to download the framework itself. Your favorite build tool can handle everything for you. Additionally, we offer a convenient setup tool that automates project creation and downloads all the necessary components. Check out our website for instructions on getting started or refer to our comprehensive wiki.
We provide the libGDX javadocs online for easy reference. Additionally, the javadocs are bundled with every libGDX distribution, ensuring smooth integration with your preferred IDE.
Community & Contribution
Stay up to date with the latest libGDX news by following our blog. For engaging discussions and support, join our official libGDX Discord.
Reporting Issues
Use the Issue Tracker here on GitHub to report any issues you encounter. Before submitting, please read our Getting Help guide, which walks you through the process of reporting an issue effectively.
Contributing to the Codebase
libGDX benefits greatly from contributions made by our dedicated developer community. We appreciate any assistance in making libGDX even better. Check out the CONTRIBUTING.md file for details on how to contribute. Note that contributing involves working directly with libGDX's source code, a process that regular users do not typically undertake. Refer to the Working with the Source article for guidance.
You can also support our infrastructure (build server, web server, test devices) by contributing financially through our Patreon!
Top Related Projects
Godot Engine – Multi-platform 2D and 3D game engine
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
Simple and Fast Multimedia Library
FNA - Accuracy-focused XNA4 reimplementation for open platforms
One framework for creating powerful cross-platform games.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot