Convert Figma logo to code with AI

libgdx logogdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines

1,204
242
1,204
29

Top Related Projects

A comprehensive path-finding library for grid based games

Industry-standard navigation-mesh toolset for games

Port of Box2D to JavaScript using Emscripten

A complete 3-D game development suite written in Java.

Quick Overview

gdx-ai is an artificial intelligence framework for game development, designed to work seamlessly with libGDX. It provides a set of AI tools and algorithms to enhance game logic, including pathfinding, steering behaviors, state machines, and behavior trees. The library aims to simplify the implementation of complex AI behaviors in games.

Pros

  • Integrates well with libGDX, a popular game development framework
  • Offers a wide range of AI algorithms and tools for game development
  • Well-documented with examples and tutorials
  • Actively maintained and supported by the community

Cons

  • Primarily focused on 2D game development, with limited 3D support
  • Learning curve can be steep for developers new to AI concepts
  • May be overkill for simple games or projects with minimal AI requirements
  • Performance can be impacted in games with a large number of AI agents

Code Examples

  1. Creating a simple state machine:
StateMachine<Entity, EntityState> stateMachine = new DefaultStateMachine<>(entity);
stateMachine.addState(EntityState.IDLE)
    .addState(EntityState.MOVE)
    .addState(EntityState.ATTACK)
    .setInitialState(EntityState.IDLE);
  1. Implementing a basic steering behavior:
Steerable<Vector2> character = new SteerableAdapter(new Vector2(100, 100));
Arrive<Vector2> arriveBehavior = new Arrive<>(character)
    .setTarget(new Vector2(200, 200))
    .setTimeToTarget(0.1f)
    .setArrivalTolerance(0.5f)
    .setDecelerationRadius(10);
  1. Creating a simple behavior tree:
BehaviorTree<MyGameObject> tree = new BehaviorTree<>(
    new Selector<>(
        new Sequence<>(
            new CheckEnemyNearby(),
            new Attack()
        ),
        new Wander()
    )
);

Getting Started

To use gdx-ai in your libGDX project:

  1. Add the dependency to your project's build.gradle file:
dependencies {
    implementation 'com.badlogicgames.gdx:gdx-ai:1.8.2'
}
  1. Import the necessary classes in your Java files:
import com.badlogic.gdx.ai.fsm.StateMachine;
import com.badlogic.gdx.ai.steer.behaviors.*;
import com.badlogic.gdx.ai.btree.BehaviorTree;
  1. Start implementing AI features in your game objects and update them in your game loop:
public class MyGameObject {
    private StateMachine<MyGameObject, MyState> stateMachine;

    public MyGameObject() {
        stateMachine = new DefaultStateMachine<>(this, MyState.IDLE);
    }

    public void update(float delta) {
        stateMachine.update();
    }
}

Competitor Comparisons

A comprehensive path-finding library for grid based games

Pros of PathFinding.js

  • Lightweight and focused specifically on pathfinding algorithms
  • Easy to integrate into web-based projects using JavaScript
  • Includes visualization tools for debugging and demonstration

Cons of PathFinding.js

  • Limited to pathfinding, lacking other AI features found in gdx-ai
  • May require additional libraries for more complex AI implementations
  • Less suitable for large-scale game development compared to gdx-ai

Code Comparison

PathFinding.js:

var finder = new PF.AStarFinder();
var path = finder.findPath(0, 0, 5, 5, grid);

gdx-ai:

PathFinder<Node> pathFinder = new IndexedAStarPathFinder<Node>(graph);
GraphPath<Node> path = new DefaultGraphPath<Node>();
pathFinder.searchNodePath(startNode, endNode, heuristic, path);

Summary

PathFinding.js is a lightweight, web-focused library for pathfinding algorithms, making it ideal for simple web-based projects or prototypes. It offers easy integration and visualization tools but lacks the broader AI capabilities of gdx-ai.

gdx-ai, on the other hand, provides a more comprehensive set of AI tools suitable for game development, including behavior trees, state machines, and steering behaviors. It's better suited for larger, more complex projects, especially those using the libGDX framework.

The choice between the two depends on the project's scope, platform, and specific AI requirements.

Industry-standard navigation-mesh toolset for games

Pros of Recastnavigation

  • Specialized in navigation mesh generation and pathfinding
  • Highly optimized for performance in complex 3D environments
  • Widely used in game development and robotics industries

Cons of Recastnavigation

  • Steeper learning curve due to its focus on low-level operations
  • Limited to navigation and pathfinding tasks
  • Less integration with game development frameworks

Code Comparison

Recastnavigation (C++):

rcConfig cfg;
cfg.cs = cellSize;
cfg.ch = cellHeight;
cfg.walkableSlopeAngle = agentMaxSlope;
rcBuildNavMeshData(&cfg, *geom, *navMesh);

gdx-ai (Java):

NavMesh navMesh = new NavMesh();
NavMeshGenerator.buildNavMesh(mesh, cellSize, agentHeight, agentRadius, agentMaxClimb, navMesh);

Summary

Recastnavigation excels in navigation mesh generation and pathfinding for complex 3D environments, making it a popular choice in game development and robotics. However, it has a steeper learning curve and focuses solely on navigation tasks. gdx-ai, while less specialized, offers a broader range of AI functionalities and easier integration with game development frameworks, particularly for LibGDX users. The choice between the two depends on the specific project requirements and the developer's familiarity with the respective ecosystems.

Port of Box2D to JavaScript using Emscripten

Pros of box2d.js

  • JavaScript-based, allowing for easy integration with web applications
  • Runs directly in the browser, enabling physics simulations without server-side processing
  • Lightweight and optimized for web environments

Cons of box2d.js

  • Limited to 2D physics simulations, unlike gdx-ai's broader AI capabilities
  • May have performance limitations compared to native implementations
  • Smaller community and fewer resources compared to gdx-ai

Code Comparison

box2d.js:

var world = new b2World(new b2Vec2(0, -10));
var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.Set(0, 4);
var body = world.CreateBody(bodyDef);

gdx-ai:

World world = new World(new Vector2(0, -10), true);
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(0, 4);
Body body = world.createBody(bodyDef);

While both libraries provide physics simulation capabilities, box2d.js focuses on 2D physics for web applications, whereas gdx-ai offers a broader range of AI functionalities for game development. The code snippets demonstrate similar syntax for creating a physics world and body, with box2d.js using JavaScript and gdx-ai using Java.

A complete 3-D game development suite written in Java.

Pros of jmonkeyengine

  • Full-featured 3D game engine with built-in physics, audio, and networking
  • Extensive documentation and active community support
  • Cross-platform compatibility (desktop, mobile, and web)

Cons of jmonkeyengine

  • Steeper learning curve due to its comprehensive feature set
  • Larger project size and potentially higher resource requirements
  • Less flexibility for integrating with other libraries or frameworks

Code Comparison

jmonkeyengine:

SimpleApplication app = new SimpleApplication() {
    @Override
    public void simpleInitApp() {
        Box box = new Box(1, 1, 1);
        Spatial cube = new Geometry("Cube", box);
        rootNode.attachChild(cube);
    }
};
app.start();

gdx-ai:

public class MyGame extends ApplicationAdapter {
    @Override
    public void create() {
        SteeringBehavior<Vector2> behavior = new Seek<Vector2>(agent, target);
        agent.setSteeringBehavior(behavior);
    }
}

The code snippets demonstrate the different focus of each library. jmonkeyengine provides a complete game development environment, while gdx-ai specializes in AI and steering behaviors for game entities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Jenkins build status (Jenkins)

An artificial intelligence framework, entirely written in Java, for game development with libGDX.

The gdxAI project is a libGDX extension living under the libGDX umbrella. However it does not force you to use that specific framework if you do not wish to do so. The libGDX jar remains an essential requirement, mostly due to the use of libGDX collections which are optimized for mobile platforms by limiting garbage creation and supporting primitive types directly, so avoiding boxing and unboxing.

GdxAI tries to be a high-performance framework providing some of the most common AI techniques used by game industry. However, in the present state of the art, the gdxAI framework covers only part of the entire game AI area, which is really huge. We've tried to focus on what matters most in game AI development, though. And more stuff will come soon.

Currently supported features are:

  • Movement AI
    • Steering Behaviors
    • Formation Motion
  • Pathfinding
    • A*
    • Hierarchical Pathfinding
    • Path Smoothing
    • Interruptible Pathfinding
  • Decision Making
    • State Machine
    • Behavior Trees
  • Infrastructure
    • Message Handling
    • Scheduling

Getting Started

News & Community

Check the libGDX blog for news and updates. You can get help on our Discord server.

Reporting Issues

Something not working quite as expected? Do you need a feature that has not been implemented yet? Check the issue tracker and add a new one if your problem is not already listed. Please try to provide a detailed description of your problem, including the steps to reproduce it.

Contributing

Awesome! If you would like to contribute with a new feature or a bugfix, fork this repo and submit a pull request. Also, before we can accept substantial code contributions, we need you to sign the libGDX Contributor License Agreement.

License

The gdxAI project is licensed under the Apache 2 License, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects. We love to get (non-mandatory) credit in case you release a game or app using gdxAI!