Karel Herink

Using Game Builder for Java ME development

This tutorial provides information about developing Java ME games using the Netbeans Mobility Pack 6.0 and the Game Builder tool. The key task in this tutorial is creating a new game level. This document is designed to get you going as quickly as possible. For more information on working with NetBeans IDE, see the Support and Docs page on the NetBeans website.

Prerequisites

This tutorial assumes you have knowledge of, or programming experience with, the following technologies.

Software Needed for the Tutorial

Open the sample Game Builder project

To create new project from samples select: Samples -> Mobile -> MIDP 2.0 Samples -> Simple Game created with Game Builder

Open the game design and browse through it's elements. A game design can contain a number of Scenes, Sprites, and Tiled Layers. The current game design contains a single scene called “forest” which is constructed from 6 layers (2 sprites and 4 tiled layers). Conceptually a scene can be thought of as a game level in our sample game.

Scene Editor

In the above image we can see the scene editor which offers several important features.

Adding a new level to the existing game

Create a new Scene

To add another level we can create a new scene by clicking the “New Scene” button on the scene editor toolbar. Call the scene “Desert” and hit the OK button. This creates an empty scene that contains no layers.

Add existing Sprites

You can add existing layers by right clicking inside the scene editor and adding either a sprite or a tiled layer. Add the two existing sprites namely “Karel” and “Thomas” to the scene. Notice that the Game Builder navigator reflects the additions by displaying the Z order of the sprites, their positions, visibility, and lock status.

Scene Editor

Create a new Tiled Layer

This scene is a little empty so lets create a new Tiled Layer to act as a sandy backdrop. To do this click the 'Create new TiledLayer' button on the scene editor toolbar.

Scene Editor

In the resulting dialog enter 'Sand' as TiledLayer name and select the '/topviewtiles.png' image. The tile size is 16x16 pixels so the preset tile width tile height should be fine. Press OK.

The Tiled Layer editor appears.

The editor contains several components:

Click the 'Paint mode' button on the toolbar and select the 'sand' tile (index 1) in the image resource panel. Then drag the mouse across the editor panel to 'paint' with the selected tile. Notice that the editor panel automatically expands if you paint past the edges. Then select another fitting tile (index 2 or 3) and paint some grassy or rocky patches. When you are done the tiled layer editor may look similar to the image below.

Scene Editor

Add new tiled layer to scene

Lets add the new tiled layer 'Sand' that we've just created to the 'Desert' scene. To do this select scene 'Desert' in the combo box above the editor. Right click inside the scene editor and select Add TiledLayer -> Sand. Drag the tiled layer Sand to X,Y position 0, 0. When you drag the 'Sand' tiled layer over the sprites 'Karel' and 'Thomas', notice that it covers both of them like a cloud above them. To fix this use the Game Builder Navigator to drag the tiled layer sand and drop it on the bottom of the sprite list. This pushes 'Sand' down in the stacking order and ensures that both sprites are visible. The resulting scene may look similar to the image below. In order to get things working nicely with emulator place the two sprites in the top-right corner of the 'Sand' layer.

Scene Editor

At this point we have created a new and very simple game level. To get the newly created level to activate during game play we need to do some coding. Luckily you can just download DemoGameCanvas.java(info) and use it to replace the one in your project. The updated code will switch the game to the 'Desert' level when main sprite 'Karel' walks to the bottom-right corner of the 'Forest' level.

Finishing up

This tutorial is not designed to show you how to create a commercial quality game as walking a sprite around with nothing much to do can get pretty boring. However, you now have a good starting place to get started with basic MIDP game development.

More information about the technologies used in this tutorial are available on following pages:

Attachments

DemoGameCanvas.java Info on DemoGameCanvas.java 13288 bytes
new_tiled_layer.png Info on new_tiled_layer.png 47167 bytes
scene.png Info on scene.png 143439 bytes
scene2.png Info on scene2.png 88612 bytes
scene3.png Info on scene3.png 116143 bytes
tiled_layer.png Info on tiled_layer.png 97872 bytes