Super Secret Communications X007Y: Using Sprite Sheet Images

This Super Secret Communications is oriented to game design.

WARNING: If you are using sprite sheets or sprite strips in your Imagine Cup 2011 game, make sure you have the rights to do so.  If you aren’t sure that the sprite sheet is available for use, then don’t use it.  Sorry, but the rules clearly state that images and music that you utilize is with the permission of the artist.  This means you need to read the license, if there are no license statement, then don’t use that material.  Anything from APPHUB can be used, so if you download and install the artwork from the “archived” products from XNA 3 and then use that artwork, then no problem and there is a lot of art in SpaceWars, Role Playing Game, Robot Game and so forth, so go mining for artwork.

Now for the fun stuff:

If you are building a game for the Imagine Cup, or for a class, it is often a good idea to start with an existing game.  You need to set aside time to learn how the existing game works.  For instance, lets take the Platformer game. 

The Platformer game for phone is an excellent starting point for people who want to build basic games for fun and profit.  You can find the Platformer game for Windows Phone at: https://create.msdn.com/en-US/education/catalog/sample/platformer

Make sure you have installed and tested Visual Studio Windows Phone Express, which is free for everyone to install from: https://create.msdn.com/en-us/home/getting_started

You might wonder why I don’t discuss Catapult Wars, the reason why is that Charles Cox has written a fine tutorial for that game.  Platformer has a few important components that I want to discuss.  Mainly, how to work with a sprite strip, which is similar to a sprite sheet but is a single column.

If we use the little white guy with the hat sprite sheet then the sheet looks like:

image

Artists generally will create the sprites in squares, and that is the case with the Platformer.  If you are looking at movie film strips for example, the image is not square and is a rectangle with specific dimensions.  If you use rectangle images, then you would make some conversion to the description of how to work with the images.

In the case of this sprite sheet, we want to determine what the height of the texture is, within the code, we use a property to return the Frame Height, which is the same as the Texture Height:

public int FrameHeight
{
      get { return Texture.Height; }
}

Once we have the Frame Height.  Now what is the FrameWidth, well for a square, FrameWidth = FrameHeight

public int Frame Width
{
        // Assume square frames.
       get { return Texture.Height; }

}

public int FrameCount
{
        get { return Texture.Width / FrameWidth; }
}

Note that you have only used Texture.Height to determine the number of images in the sprite strip, what if you have a sprite sheet?  Then you would need to know the number of rows, where each row is the sprite strip, and even though that is the common way of distribution of the sprites, this blog will discuss only the use of Sprite Strips.

To see how this code is utilized, download the Platformer from the link shown above and then look at the animator.cs class.

You can see that the “animator” class does nothing except for getting the information about the sprite strip, it doesn’t show the image.

Now you can utilize this information, in Platformer, the sprite strip is use in the AnimationPlayer.cs,  I will discuss how this is done in a later Secret Communications.

End of Secret Communication X007Y

NNNN