By Ronald and Samuel Cook
back to the main tutorial guide page .
Reference: This is the fifth tutorial on how to work with the GTCS1Lib library. It is assumed you have read and understand the previous four tutorials:
Goals : This tutorial concentrates on describing how to work with Sprite Sheets:
1. Obtain the example code
Download
and unzip the zip file and you will see an ExampleProgram folder. Open
the ExampleProgram folder, the EXE folder contains the compiled
program and you can double click on the .sln file to work with
the source code.
If
you double click and run the executable program, you will observe:
|
However,
the sprite will actually be moving, and you can use the dpad on a controller to
change the direction he walks in.
2. The Source Code Files/Structure
Take a look at the ExampleProgram folder that you have unzipped and you will see a structure identicle to that of the previous tutorials.
3. The Solution Explorer:
Now double click on the *.sln file in the ExampleProgram folder, to start the project in the IDE. Notice the structure of the SolutionExplorer follows the source code folder structure we have examined:
|
As illustrated in the above figure, you will notice the Textures folder and the Sprites.png file. The process of including the *.png files into the project works identical to that of *.jpg Texture files, where you would right-mouse-button click on the Resources folder and add the existing Textures folder. Any *.png files can be included in this folder (and thus into your project).
As
in the case for any assets, do not forget
to open the associated properties and change the Build Action to Content,
and Copy to Output Directory to Copy if newer.
Particles: in the
XNACS1Rectangle.SetTextureSpriteSheet(String SpriteSheetTexture,...)
method, the
SpriteSheetTexture refers to names of these *.png files. Notice that as in the
case of .jpg image files where we identify the images by their names without
the extension, we will also refer the Sprite Sheets by their file names without
the .png extension.
4. Examine the Predefined Emitters:
We
are finally ready to examine our source code for Sprite Sheets. To
declare a Spirte Sheet use the following code:
public class Game1
: XNACS1Base |
The XNACS1Rectangle.SetTextureSpriteSheet(String SpriteSheetTexture, int numColumns, int numRows, int padding) arguments are pretty straightforward.
You may also notice this line of code, "Sprite.SetTextureSpriteAnimationFrames(0, 0, 1, 0, 5, SpriteSheetAnimationMode.AnimateForward);" The first five parameters sets the current animation of your Sprite object to a sprite from the sprite sheet, the last parameter enables the Sprite object to animate, forward in this case.
The XNACS1Rectangle.SetTextureSpriteAnimationFrames(int beginX, int beginY, int endX, int endY, int ticksPerFrame, SpriteSheetAnimationMode mode) arguments are a little more confusing.
The following is the code that causes the sprite to change directions when a
direction on the dpad is pressed. It is one example of how you can use
the sprite sheet animations.
protected override void
UpdateWorld() |
Project
home page>: The
Game-Themed Introductory Programming Project.
Kelvin Sung |
Michael Panitz |
|
This work is supported in part by a grant from Microsoft
Research under the Computer Gaming Curriculum in Computer Science RFP, Award
Number 15871 and 16531. |
|