Empty Your Mind Tutorial 3
From SwinGame
This tutorial will teach you how to use the SwinGameSDK to develop a simple danmaku game which looks cool. At the end of this tutorial you should be able to use pascal to implement your own space invaders or scrolling shooter style game which makes use of Vectors, animated Sprites, SoundEffects, and Music.
Contents |
Preparing The Background Sprites
Background image in a scrolling shooter game is very important. I want a single seamless image scrolling in the game we will be making. I will be using this image in this tutorial. To create a scrolling effect, we will need to setup two sprites. This will be explained later in this tutorial. The following code should go into your LoadGame procedure. As you can see, we are creating sprites and adding it to the list of images. We will be using this array of bitmap to manage images such as HUD.
game.images[0] := CreateSprite(GameImage('Map')); game.images[1] := CreateSprite(GameImage('Map'));
This will create two sprites which contains the same image. Do not forget to set the length of the images array.
Drawing The Background
The following steps must be taken to draw the seamless background.
- Move the Sprite 1 (10 pixel down)
- Check if the Sprite 1 has disappeared from the screen
- If the Sprite 1 is off the screen, reset the position of the Sprite 1 (i.e. set the coordinate to 0, 0)
- Move the Sprite 2 on the Sprite 1 (therefore, the bottom of the Sprite 2 will attach to the top of the Sprite 1)
- Draw Sprite 1
- Draw Sprite 2
The implementation of the steps:
procedure UpdateBackground(var images : Array of Sprite); const BACKGROUNDSPEED = 10; begin //Slide the first background sprite by the background speed images[0].yPos := images[0].yPos + BACKGROUNDSPEED; //Reset the position of the first background sprite if it has //reachead the bottom if images[0].yPos >= ScreenHeight() then images[0].yPos := 0; //Set the second background position so the background is seamless images[1].yPos := images[0].yPos - ScreenHeight(); //Draw background sprites DrawSprite(images[0]); DrawSprite(images[1]); end;
Summary
In this tutorial, I have gone through:
- The algorithm to scroll the background
The current project files can be downloaded from here.

