Tutorial 2 - Creating and Loading a Room File

In this tutorial, you will be introduced to the Qaf Room Editor and some of its features.

The Base Path

The Editor is a separate application, which can be accessed by running editor/RoomEditor.exe. If this is the first time the Editor is run, you will be greeted by the following dialog:

tut02basepath.png

You should enter the directory where your executable is generated. For instance, if your game's resources are arranged in the same manner as the structure presented in Tutorial 1 - Basic Qaf Setup, the base path would be the project's Debug directory.

The base path can be changed later by clicking File -> Change base path.

Obstacles and Background Layers

This is what the window should look like now:

tut02emptyroom.png

The Editor will start with a default 640x480 room. The screen, in turn, is further divided into the elementary structural components of the game's environment: The obstacle blocks. The level designer is allowed to choose from a set of primitives when outlining the backgrounds' structure; these are visible in the Editor's lower-left panel. You can select a primitive by clicking on it, and then place it on the room's grid by "drawing" with the left mouse button.

tut02obstacles.png

With the floor and walls set up, it's time to draw the actual backgrounds.

Click on the Room menu and choose to create a New BG layer. You should see the following dialog:

tut02newbglayer.png

Most of these elements are pretty self-explanatory. As noted above, the source image must be placed somewhere within the base path's subdirectories. (If you're following the previous tutorial, that would be Debug, and you'd have to copy the image files into that directory.)

Go ahead and create three background layers with the following parameters:

Source image Parallax factor Tile size
background00.png 1.0 x 1.0 32 x 32
background01.png 0.8 x 0.8 320 x 240
background_moon.png 0 x 0 640 x 480

You will notice that a tab is added to the lower-left panel every time you add a background layer. Clicking on a tab displays the tiles stored in that layer, and allows you to click-select-and-click-draw like you did with the obstacle blocks. Now, let your creative side run loose... or just replicate the room below:

tut02layers.png

tut02tip_pick.png
Tip
You can select a tile by holding down Ctrl and clicking on the editor's main area.

You'll notice I placed the tiles on layer #0 so that they would overlap the obstacle blocks. This is deliberate, and the reason will become clear when we deal with collisions in tutorial #6.

OK, the room is ready. Save it as tut02.qr in the same directory as your executable and exit the Room Editor.

Loading and Displaying the Room

This is actually the easiest part. After initializing Qaf, you just need to tell it which room to load:

    // Set up the environment:
    Environment::initialize( false, true );
    
    // Load the room:
    Environment::loadRoom( "tut02.qr" );

Other than, that, very little has changed in the code from the first tutorial.

See the full source code for this tutorial in the file: tutorials/tutorial02.cpp


Generated on Sun Mar 25 12:32:13 2007 for Qaf Framework by  doxygen 1.5.1-p1