Creating A Backdrop

Click here to load the completed tutorial directly into the editor SWARM-03.DBA. If you want to step through and make the modifications, click here to load SWARM-02.DBA.

To make the backdrop of our game more interesting, we shall add some stars to replace the black screen we currently see. A number of media types have been provided with this tutorial stored in folders called BMP, OBJ and WAV. These folders contain graphics and sound files that have been assembled for you to create this game. Contained within the BMP folder is a bitmap file called ‘stars.bmp’ that contains a picture of stars. We first need to load this bitmap into memory and store it as an image.

Replace the first REM * HERE * line to read:
rem Load stars image
LOAD IMAGE "bmp\stars.bmp",1

If you check your program by pressing F4, you can make sure your program is free of syntax errors. Syntax errors are caused when the line you type is not recognised by DarkBASIC, often caused by misspelled commands.

Now you want to see your stars. We can quickly see this effect by adding two more commands to our program.

Replace the second REM * HERE * line to read:
rem Create star backdrop
BACKDROP ON
TEXTURE BACKDROP 1

The first command BACKDROP ON switches on the backdrop that will fill the screen with the default colour of blue. The second command TEXTURE BACKDROP replaces the default blue colour with the image containing the stars bitmap we loaded earlier.

We can make our program look much nicer if we group commands together that perform a single task. By using Subroutines, we can do just that. Replace the two commands you have just entered to read:

rem Create star backdrop
GOSUB _create_backdrop
Replace the third REM * HERE * line to read:
rem Texture backdrop with stars image
BACKDROP ON
TEXTURE BACKDROP 1

You can see how we have moved the two backdrop commands into the subroutine called _create_backdrop. The command GOSUB will instruct the program to jump to the start of this subroutine and run the contents. When the program pointer eventually reads the RETURN command, it will jump back to where it came from. Gosub and Subroutines are a good way of organising your thoughts as well as your program.

It is much easier to read a single well described gosub call than several lines of commands, and allows you to focus on the big picture.

Click Here For The Next Tutorial Scrolling A Backdrop.