| Most games are not much fun if they are text only so using Graphics is something that must be done sometime. And with the kind of graphics you can buy or make these days, imagine the "wow factor", you can achieve. This is a basic example on how to load and show an image on screen.
To demonstrate this, create an image,about 60x75 pixels in size (remember any blank space needs to be filled black) or use the example pictures (and source code,tutorial text for this tutorial) from here .
We start by setting the graphics mode.Setting it to 800,600 means that the Xaxis contains 800 pixels and Yaxis contains 600 pixels.
|
|
Then to avoid flickering from the screen constantly refreshing we'll need to work in the backbuffer. Use the following command to set the buffer.
|
|
| To display an image it first needs to be loaded into the computer's memory. The loadimage command has three sections: Section A is the name (also called a handle) which it will be reffered to in your program. player is used in this example. Section B is the actual command LoadImage and then Section C is the file name surrounded by double quotes and brackets. Here's an example |
|
If there is any blank space in the picture it needs to be black (the same colour as the background)
Remember that the demo version of Blitz Basic supports BMP files; the full retail version of Blitz Basic supports JPG and PNG format as well.
Then we need To start the on screen program. To start we'll need to say While something happens. In this example while the Esc. key isn't pressed |
|
While comes with a partner Wend so at the end of the loop we'll need to put Wend
Next clear the screen of any thing that might be on it .
|
|
And draw the image. Drawimage contains several sections: SectionA is DrawImage, the command, SectionB is the name which you gave the image in the LoadImage command, SectionC is the X axis location and SectionD is the Y axis location. For this example the X and Y axis will be the location of the mouse pointer
|
|
And flip the back and front buffers using the 'Flip' command
|
|
Wend makes the program go back to the While
|
|
|
Putting End at the end of your program gets rid of the 'Program has ended' message window
|
|
There are many more things you can do with images. Try moving them,putting more than one on screen and having images appear and disappear when you press a key.
|
|
|
|
|