Game Development Reference
In-Depth Information
this .sheetColumns = int .Parse(colrow[0]);
In case the length is two, we also need to parse the second string element, and store
it in the sheetRows variable:
if (colrow.Length == 2)
this .sheetRows = int .Parse(colrow[1]);
Yet another possibility is that the array contains more than two elements. We do not
handle that situation in the constructor (meaning that in that case, we only store the
number of columns). In the SpriteGameObject class, we now replace the Texture2D
member variable by a variable of type SpriteSheet :
protected SpriteSheet sprite;
And we create an instance of the sprite sheet in the constructor (only if a non-empty
asset name was passed along):
if (assetname != "")
sprite = new SpriteSheet(assetname, sheetIndex);
else
sprite = null ;
19.4 Managing the Sprite Sheet
We have already seen in the Jewel Jam game how to deal with a strip of sprites. We
had to change the Draw method to draw only part of the sprite. Also, we changed the
Width property to take the strip length into account. Here, we are going to add more
or less the same functionality to the SpriteSheet class, except that we need to do it for
two dimensions instead of one. The first thing that we need to do is to add a Width
and Height property to the class that take into account the column and row numbers
of the sprite sheet:
public int Width
{
get
{
return sprite.Width / sheetColumns;
}
}
public int Height
{
get
{
return sprite.Height / sheetRows;
}
}
Search WWH ::




Custom Search