Scrolling A Backdrop

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

Now we have a backdrop in place, we can start to inject a little movement into our game. To give the impression that we are souring up the screen, we shall make our backdrop scroll downwards.

To find markers in the program, you can use the find tool CTRL+'F' to look for the keyword 'HERE'. You can then use the find next tool CTRL+'N' to skip each occurrence of the keyword until you find the marker you're interested in.

Replace the line REM * HERE B * to read:
rem Control star backdrop
GOSUB _control_backdrop

And replace the line REM * HERE D * to read:
rem Scroll star backdrop
INC starscrolly#,1.0
SCROLL BACKDROP 0,0-starscrolly#

As you can see, we have made a separate subroutine to handle the scrolling of the backdrop called _control_backdrop. By placing the GOSUB call inside our main loop, this subroutine will be called over and over again.

The secret of moving parts in any game is that everything is done a little at a time. All we wish to do is shift the backdrop ever so slightly each time our game loops.

In order to keep track of these little changes to the backdrop, a variable is used to store the current scroll position. The STARSCROLLY# variable holds a value that tells us how far the backdrop ought to be scrolled. The INC command will increment the value contained in this variable by 1.0 each time it is called.

The SCROLL BACKDROP command then takes the value of the variable and uses it to adjust the current scroll position of the backdrop. Both the INC and SCROLL BACKDROP commands take two parameters. Parameters are values that the command requires in order to carry out the instruction.

In the case of the INC command, the compiler needs to know the variable to increment and the amount to increment by.

In the case of the SCROLL BACKDROP command, the compiler needs to know the horizontal scroll value and the vertical scroll value to be applied. As you can see, we keep the X scroll value at zero, but modify the Y scroll value based on the value stored in STARSCROLLY#.

Because we want our backdrop to scroll down and not up, we convert the value to a negative by deducting it from zero using the formula 0-STARSCROLLY#. Now we need to make the backdrop scroll smoothly by controlling the synchronisation of the screen.

Replace the line REM * HERE A * with the line SYNC ON
Replace the line REM * HERE D * with the line SYNC

These two additions instruct the compiler that you only wish to update the screen at the end of your main loop. Without these commands, your compiler will attempt to update the screen after every command, which will cause your program to slow down as it grows in size and complexity.

Click Here For The Next Tutorial Creating The Ship.