Thursday, May 27, 2010

Basic4GL Basics Tutorial 3 - Load a Image to the Screen

This tutorial teaches you how to load a image to the screen. Make sure you have gone here and here before learning how to load a image and place it on the screen.

Ok so loading a image in Basic4GL is actually a lot easier than most of other programming languages. This so because of the way the sprite library is made to make sprite games. Also did you know you can create complete games using the sprite library and without knowing a single peice of OpenGL code. So lets continue with this tutorial by saving a image from below.




Now save it as a .png as thats the file format I like personally. Make sure Basic4GL is open and place the following code into it. Preferably typing it in and not copying and pasting it.

dim block

block = NewSprite(LoadTex("block.png"))
SprSetPos(200, 200)
BindSprite(block)

ok so lets explain this code for you.
firstly you declared a variable and told Basic4GL you wanted it to make a NewSprite. Then you toald it load a image called block using the LoadTex function. You then selected the point in the screen where you wanted to place the loaded image. BindSprite doesn't need to be called but if you wanted multiple images on the screen at once it has to be used. So it's just good practise.
Now if you save this program to the desktop in a folder called test. Pleae place the block image in here and save your basic4GL file with whatever name you like. If you followed the tutorial correctly your program should look like below.


So now this part of the tutorial is finnished. You can now place your images you make onto the screen. There is quite a lot of image formats that Basic4GL can load such as .png, .jpg, .bmp, .gif and several others that I have forgotten about.

No comments:

Post a Comment