Every game within the last five to six years at least uses some form of sprites and textures. These are vital to adding color and visual graphics to any game project. Using the Truevision 3D engine you can easily load and draw texture images anywhere on the screen. This straight forward guide will show you all you need to know to achieve this.
Step One - Initializing the 2D Screen
Assuming you have already added Truevision 3D to your project and you have already started coding your game then you just need to initialize the 2D screen. Add this source code to your object and variable declarations,
TVScreen2DImmediate Screen_HUD = new TVScreen2DImmediate();
TVTextureFactory Texures = new TVTextureFactory();
That's all for the declarations, now in your loading void or function use the following code whenever you want to load a specific image file.
Texures.LoadTexture(Application.StartupPath + "\\Textures\\myimage.jpg", "myimage");
You will obviously need to insert your own path and desired name for the new texture. You can also specify the height, width, and transparency of the new texture by filling in the additional optional arguments.
Step Two - Rendering the Sprite
Now that the proper objects are defined and the textures loaded you can begin to render the texture anywhere on the user's screen. In your render function implement this code,
Screen_HUD.Action_Begin2D();
Screen_HUD.Draw_Texture(Globals.GetTex("myimage"), this.Width / 2, this.Height / 2, this.Width / 2 + 32, this.Height / 2 + 32);
Screen_HUD.Action_End2D();
Make sure to replace where necessary with your variables. The code given above will draw the myimage texture directly at the center of the screen. You could use this type of code to draw a crosshair image in your first person shooter games.
Make sure to always execute the Draw_Texture function between the Screen_HUD.Action_Begin2D(); and Screen_HUD.Action_End2D(); methods for the 2D screen engine to be able to execute properly.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
- 2d Geometry for Game Programming
- A Rational Cosmology: The Ubiquitous Qualities of Volume, Length, Width, and Height
- WonderCon 2009: Disney's Return to 2D Animation
- Odin Sphere (PS2): Brings New Life to 2D Games
- Photoshop Tutorial : How to Create a 3D Text Using a 2D Design Program
- New Super Mario Bros Wii Review - Mario's Triumphant Return to 2D
- Using Google's New Calendar Function



