Developing Game-Themed Applications with XNA Game Studio
Section III: The Block Breaker
Game
e. Including file texture images
back to workshop main page
References:
Goals: In this tutorial we want to experience:
- Working with file textures!
Library function to notice:
Implementation:
-
Including texture resources: Under the Solution Explorer, open the
Content tab,
- Right-mouse-click on the Resources folder:
-
Add new folder: Textures.
-
Add textures: Right-mouse-click over the Textures folder: Add
Existing Items
-
Browse and add the following two images (under TextureImages
folder):
 |
 |
 |
| bgTexture.jpg |
blockTexture.jpg |
paddleTexture.jpg |
- The above actions will include these two images as part of the
project. Now, we can use these images in our project.
-
Background Texture: Game1.cs:
- InitializeWorld: include the following line:
- By setting the
BackgroundTexture the application will automatically use this
image as the background.
- Block Texture: Block.cs
- Instance variable:
- Constructor: initialize
- Draw:
- last parameter of DrawTriangle, uses the new texture.
- Paddle without texture: Paddle.cs:
Recall that the Paddle class is a subclass from the
Block class. By include a texture for the blocks, paddle will also
display the same texture. This is kind of ugly, so let's change the
texture for the padde:
Lesson Learned:
There are two things we should keep in mind when working with file textures:
- Inclusion into the project: we must add each texture image into the
project. These images must be added to the Textures
folder under Content/Resources.
- Using the texture image: Notice we use the texture image without
the file name extension.
This document and the related materials are developed with support from
Microsoft Research Computer Gaming Initiative under the Computer Gaming
Curriculum in Computer Science RFP, Award Number 15871, and 16531.