This toturial was written for me by Imran Khan (firstname.lastname@example.org,
Surface With Images:
We have learnt how to make a surface and how to display it. In this Section we will learn how to make surface with images.There can be more then 1 surfaces, Like 1 surface show the background, 1 show the character, 1 show the enemy and so on.Every Surface contains one image ( depends upon your requirements ).
All the codes are continuation of the previous code. Now we add something to 2 methods, ' Init( ) ' and 'Show Surface( ) '.In Init we will initiate new surface and in showSurface we will display that Surface.
First of all we will declare a instance for new surface
We just added one line ' Dim charsurface As Surface ' which is the surface on which we draw our picture.
Now on Init( ) method.
All the method is same except the last 3lines. First we clear our surface desciption variable by calling ' sdesc.clear( ) ' , so we can use it to describe another surface then we set the surface as simple surface , not a backbuffer. In the next line we create new instance of the Surface class, First Argument take the path of the Bitmap(you can change the path, depends where you bitmap is placed ),2nd argument is the Surface Description and the last argument is the Device object which we are using.
Add more 3 lines if you want more surfaces with pictures.
Now we add some lines to ShowSurface( ) method to show our new surface.
You know the First 2 lines, 3rd line shows how to draw Surface on Backbuffer ( Secondary Buffer ), First 2 arugments are x & y cordinated ( where you want to show your picture on screen ), 3rd argument is the surface object,4th argument is the Flag.If you specify DoNotWait then the surface will we drawn faster, the device will not wait until the surface is not being used by anything else. Another flag is ' Wait ' , which is opposite to 'DoNotWait' flag. You can also use method ' Draw ' to draw Bitmap Surface but ' DrawFast ' draw faster then the ' Draw ' method coz ' Draw ' performs BitBlockTransfer for drawing.
You can use other methods to draw circle ,rectangle etc by using there methods.( which is easy )
The next 2 lines are for drawing Text on the Screen. First we set the color of the surface so that the text will be in Black. Next line shows the method to DrawText on screen. First 2 arguments of this method are x and y cordinated ( where you want to show your text on screen ) and the last argument indicates whether to draw the text at the last position that wasnt used yet, if you set this to True there is absolutely no point in setting the x and y coordinates.
Rest of the program is same as previous.
Now when you run this program you will the image in the middle and a text written on right lower corner.
|Correspondence about this page
This site may have errors. Don't use for critical systems.