Skip to content
Daan van Yperen edited this page May 31, 2019 · 2 revisions

Hello World example

This guide creates the smallest possible project for artemis-odb. It assumes you are aware how to set up an empty Java project and add dependencies.

You can find a gradle version of this project in the https://github.com/DaanVanYperen/artemis-odb-examples/ folder.

1. Set up your project

Create a new blank project in IntellIJ or Eclipse and add a dependency on net.onedaybeard.artemis:artemis-odb:2.2.0.

2. Create a component

Create Hello.java in package my.game.components containing:

public class Hello extends Component {
    public String message;
    public void set(String message) {
        this.message = message;
    }
}

3. Create a system

Create HelloWorldSystem.java in package my.game.systems containing:

@All(Hello.class)
public class HelloWorldSystem extends IteratingSystem {

    protected ComponentMapper<Hello> mHello;

    @Override
    protected void process(int id) {
        System.out.print(mHello.get(id).message);
    }
}

4. Create a game launcher

Create GameLauncher .java in package my.game containing:

public class GameLauncher {

    public static void main( String[] args ) {

        // 1. Register any plugins, setup the world.
        WorldConfiguration setup = new WorldConfigurationBuilder()
                .with(new HelloWorldSystem())
                .build();

        // 2. Create the world.
        World world = new World(setup);

        // 3. Create entity. You can do it here or inside systems.
        int entityId = world.create();
        world.edit(entityId).create(Hello.class).message = "\n\rHello world!\n\r";

        // 4. Run the world. HelloWorldSystem should print the hello world message.
        world.process();
    }
}

5. Run it!

Run GameLauncher#main. The world should process and should print Hello World.

Clone this wiki locally