This toturial was written for me by Imran Khan (email@example.com,
In this section we will learn how to show Background.One is thinking that the mechanism to show background must be same a to show a bitmap. Ya it is, but with some changes, because the background scroll with the movement of the character.
First we declare some instances
As we define rectangle for a character , here we also define a instance of Rectangle class for background to make frames. So that background will move with the movement of the character.
Next we define a surface for background.
Next we define a integer , we will show the use later.
First we create a method name Background( ).
Call the Background method from " Init( ) ", by writing " Background( )" at the last of the Init( ) method.
First line create a new surfacedescription instance for background surface. Next we declare that the surface is simple not a backbuffer. 3rd line we create new surface as we done before. The only new line is last one.4th line set the size of the rectangle, this assumes the part of bitmap you want to display is 800x600 ( size of the screen ). Means it will show that size of frame every time when character moves.
Now we will see how to show the picture.
backrect.X = xaxis , it tells to start drawin from
the beginning of the bitmap.We take a variable so that every time the
character moves the xaxis value will be changed and the backrect.X value
will be change so that we will see the background scrolling.
Now When the user hit the right arrow the character move(we have done this ) and the xaxis value will also change.
xaxis += 10,whenever user press right key , 10 will be added to this variable so when we call ' ShowSurface( ) ' this value will be copied to
backrect.X = xaxis.
and the image will be shown from that postion.
the next thing we added is :
If xaxis > 1600 Then
it is the limit of the background here, coz i have made only 2 scenes so the total lenght of the image will be '1600'.
Now if you execute your program you will see a complete game features ( excepy sound ... ).
|Correspondence about this page|
This site may have errors. Don't use for critical systems.