Artenus 2D Framework
Artenus Getting Started

Adding Graphics and Sound

Graphics and sound are important part of any game. Handling these resources can be difficult considering the lifecycle management complications of Android. That is why Artenus aims to manage this internally and save the programmer a great deal of trouble. Before we begin, download the following files, and extract them into the raw resource directory of the app you created in the previous step. If you don't have such a directory, create one under res.

Example Textures

These are the textures we are going to need for this tutorial.

Example Sound

This is the sound file we are going to need for this tutorial.

Adding graphics

Artenus supports both raster and vector graphics for textures. Your textures can be PNG or JPEG as well as SVG. However, it is recommended to use SVG where you can as this helps the framework to properly adapt the resolution of the textures to different screen sizes, which results in crisp graphics regardless of what device runs your game. If you do include raster graphics, NEVER use resource qualifiers. Include all your graphics in the drawable resource folder, and only include one version, which has the maximum resolution you are using the texture with in the game.

Artenus also supports a specific type of vector graphics, called font. Artenus fonts are ordinary SVG files, with the addition of a comment in the XML which specifies letter locations in the graphics. More information about fonts can be found in the Artenus reference.

In order for textures to be used in an Artenus game, they should be declared first. There are two methods of declaring graphics in the framework: global declaration, and local declaration. Global textures are those that are fixed throughout the game, that is, they are used in most or all scenes. It is recommended to limit the number of these resources as much as possible, to avoid keeping a large amount of data in the memory. Global textures should be declared in the onLoadStage method of the stage manager. To demonstrate how you can add global textures and fonts, we now add them to our little project. So, open the main activity and modify onLoadStage as follows:

@Override
public void onLoadStage(Stage stage) {
    // Add global textures to the game.
    TextureManager.add(
            R.raw.play,
            R.raw.font_letters
    );
}

Note that we only added two textures here, and not all of them. The rest of the textures will be declared locally for scenes that need them. We will see how to do that later on. What you should know for now is that these textures load when the game begins (at the main loading screen), and whenever the context is lost. They also reside in the memory as long as the app is active.

Adding sound

Like graphics, sound should also be declared to the interface before it is used. However, unlike textures, all sound assets can (and should) be declared in onLoadStage. Artenus treats sound effects and background music differently. Sound effects are declared pretty much in the same format as textures. For example, for our project's sound effect, we should write:

// Add sounds to the game
SoundManager.add(R.raw.step);

Once added, you can use the playSound method to play the sound. For example:

// Play the step sound
SoundManager.playSound(R.raw.step);

// Play the step sound with a specific volume
SoundManager.playSound(R.raw.step, 50);

Our project does not have any background music. But if it did, we wouldn't need to declare it. Background music in an Artenus project goes into the assets directory, and not resources. To play a music we simply give the address of the asset file, for example:

SoundManager.playMusic("bg.ogg");

Above method only plays the music once, just like a sound effect. If you want to play the music in a loop, You need to use the setMusic method instead. Below is an example:

SoundManager.setMusic("bg.mp3");

Now that we have declared textures and sound effects for our game, we can start creating scenes.

Previous: Starting an Artenus Project Next: Creating the First Scene