Artenus 2D Framework
Artenus Getting Started

Starting an Artenus Project

This short tutorial helps you familiarize yourself with the Artenus framework through a simple project. To begin, open Android Studio and create a new project (File > New > New Project). In the first screen you choose a name and a package name for your project. In the second page, make sure that you choose API level 9 or higher for your minimum SDK. When it comes to selecting an activity, click the Add No Activity option. Android Studio adds too much bulk for an activity that we don't need. When you are done, click Finish.

Adding Artenus

Download Artenus either from the GitHub repository, or from this link. The latter is the version this documentation is written and tested for. Once downloaded, extract it in your project directory, next to app. The extracted directory name includes version number. Rename it to artenus without any suffix.

Open settings.gradle of your project, and add the following to it:

include ':artenus'

Syncing the project now will add the artenus module to it. You still need to add a reference to this module to your app. To do this, open build.gradle of your app module, and add the following inside the dependencies block:

compile project(':artenus')

Now, sync your project before you continue. This will enable you to use Artenus classes in your app.

Creating the activity

Next step is to create an activity, since we asked Android Studio not to do so. Right-click your main package name and click New > Java Class. Name the class MainActivity, and fill it with the following basic implementation (note that we extend Artenus, and not Android's Activity class):

/**
 * The game's main entry point.
 */
public class MainActivity extends Artenus {
    @Override
    protected void init(Stage stage) {

    }
}

By default, Artenus shows a splash screen at the beginning of the game. While it is recommended to keep this splash screen as an attribution to the framework, you may suppress it by adding the following optional constructor.

public MainActivity() {
    super(true);
}

The boolean argument of the superclass constructor specifies whether to skip the splash screen.

What we implemented so far is not complete. One of the key components of an Artenus game is a stage manager. The role of the stage manager is to bootstrap the game. As the main activity is very small, it is convenient to let it be the stage manager as well. For this you need to implement the corresponding interface, and write the code for each function. You should also assign the manager in the init method. Your activity code would then look like the following:

/**
 * The game's main entry point.
 */
public class MainActivity extends Artenus implements StageManager {
    @Override
    protected void init(Stage stage) {
        stage.setManager(this);
    }

    @Override
    public void onLoadStage(Stage stage) {
        // TODO: Load game resource
    }

    @Override
    public Scene createInitialScene(Stage stage) {
        // TODO: Create the first scene
        return null;
    }

    @Override
    public void onEvent(Stage stage, StageEvents event) { }
}

Updating the manifest file

Finally, you need to declare the activity in your manifest file. Open your AndroidManifest.xml and add the following to it, within the <application> tag:

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
        android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

To support large screens (and be listed in the app-store for those devices), it is also recommended to add the following to your manifest.

<supports-screens android:largeScreens="true" android:xlargeScreens="true" />

Note that you still cannot run this game as you have not created a scene. But we will do that later in this tutorial.

Next: Adding Graphics and Sound