Game Development Reference
In-Depth Information
22.6.5 Loading Different Kinds of Tiles
We can use the switch -instruction to load all the different tiles and game objects. For
each character, we need to perform a different task. For example, when the character
'.' is read, we need to create a normal tile. The following instructions do that:
t= new Tile("Sprites/spr_field@2", 0, "", (row+col) % 2);
tilefield.Add(t, col, row);
break ;
The sprite used for the tile is a strip consisting of two different sprites. By switching
the sheet index using the formula (row + col) % 2 , we get the alternating checkerboard
pattern as can be seen when you run the example project belonging to this chapter.
Another example is adding a background (transparent) sprite:
t= new Tile("Sprites/spr_wall");
t.TileType = TileType.Background;
tilefield.Add(t, col, row);
break ;
Although the background sprite is invisible, we still load a sprite belonging to this
tile. Why is that? The reason is that the Tile class inherits from the SpriteGameObject
class, which requires a sprite. Of course, another option would be to modify the
SpriteGameObject class so that it can deal with a sprite that is null . However, in this
case, we chose to follow the simple solution of just providing a sprite, even if the
player will never see it.
When we have to place a penguin, actually two things need to be done:
we need to place a normal tile
we need to place a penguin
 
Search WWH ::




Custom Search