Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

IsoTileSet Class Reference

The tileset class simplifies loading bitmap files that contain several tiles. More...

#include <IsoTileSet.h>

Collaboration diagram for IsoTileSet:

Collaboration graph
[legend]
List of all members.

Public Methods

 IsoTileSet ()
 For the free function. More...

 ~IsoTileSet ()
bool loadTileset (char *name)
 Loads the tileset from a file. More...

bool reloadTileset ()
 If the surface was lost, reloads it, but does not reparse the file. More...

bool unloadTileset ()
 Performs all the necessary clean-up operations. More...

Uint32 getTileCount ()
 Returns the number of tiles in the tileset. More...

TILEINFOgetTileList ()
 Returns the list of tiles. More...

SDL_Surface * getSurface ()
 Returns the surface on which the tilesey resides. More...

char * getFileName ()
 Returns the name of the file containing the tileset in a null-terminated string. More...

void putTile (SDL_Surface *destinationSurface, int xCoord, int yCoord, int tileNumber)
 Puts the tile specified onto the surface passed in. More...


Detailed Description

The tileset class simplifies loading bitmap files that contain several tiles.

It is a fairly flexible class, but it does impose certain restrictions on the way the file is organized. First of all, there needs to be a set of control pixels in the upper-right corner of the image. The control pixels start at the coordinate (width-1, 0) and go down from there in the following order: transparency pixel, empty-region pixel, outside anchor pixel, used-region pixel, inside anchor pixel; five in all. The transparency pixel is used for color-keying, and all the pixels of that color in the image will be made transparent. The outside and inside anchor pixels do the same thing currently, and are used to denote the image anchor. When the tile is blitted using the putTile method, the anchor has the coordinates passed in to the method, and the rest of the image is drawn relatively to it. In other words, suppose we blit to rectangular tiles using the same target coordinates. One of the tiles has its anchor in the top-left corner, and the other - in the center. Then the center of the latter tile will coincide with the top-left corner of the former tile. The empty-region and used-region pixels are used to denote where the useful areas of the tile are, and which ones can be discarded. The reason for that is that the tiles in the tileset file have to be arranged in a table. In other words, all tiles in one column have to be the same width, and all the tiles in one row have to be the same height. That is not to say, however, that the width and the height have to be the equal, or that the tiles in different rows have to have the same height, and in different columns - the same width. Suppose a game has only two tiles. We can arrange them in a column. One of the tiles is square, and the other - a very thin rectangle. Then, we could mark the whole first tile as used, and for the second tile - only the space that is actually used up. Since we arranged the tiles in a column, the widths of the tiles have to be the same. However, we can mark the unused areas of the thin tile with the unused-area pixel color, and they will be discarded when blitting.

The above description seems rather confusing, despite being fairly precise. Please refer to the "CaveMan_Animation.bmp" image to see how a tileset image should be organized. A picture, after all is worth a thousand words.

Author:
Vovansim (aka Scorpion)
Version:
1.0
Date:
May 15, 2003
Examples:

TileEngineExample.cpp, and TileSetExample.cpp.

Definition at line 77 of file IsoTileSet.h.


Constructor & Destructor Documentation

IsoTileSet::IsoTileSet  
 

For the free function.

Definition at line 21 of file IsoTileSet.cpp.

IsoTileSet::~IsoTileSet  
 

Definition at line 28 of file IsoTileSet.cpp.

References unloadTileset.


Member Function Documentation

char * IsoTileSet::getFileName  
 

Returns the name of the file containing the tileset in a null-terminated string.

Definition at line 365 of file IsoTileSet.cpp.

SDL_Surface * IsoTileSet::getSurface  
 

Returns the surface on which the tilesey resides.

Definition at line 359 of file IsoTileSet.cpp.

Uint32 IsoTileSet::getTileCount  
 

Returns the number of tiles in the tileset.

Definition at line 349 of file IsoTileSet.cpp.

Referenced by initializeEngine.

TILEINFO * IsoTileSet::getTileList  
 

Returns the list of tiles.

Definition at line 354 of file IsoTileSet.cpp.

Referenced by initializeEngine, and programLoop.

bool IsoTileSet::loadTileset char *    name
 

Loads the tileset from a file.

Definition at line 39 of file IsoTileSet.cpp.

References RECT::bottom, CopyRect, getPixel, RECT::left, ImageCanvas::loadImage, OffsetRect, TILEINFO::ptAnchor, TILEINFO::rcSrc, RECT::right, RECT::top, unloadTileset, POINT::x, and POINT::y.

Referenced by loadTileSets.

void IsoTileSet::putTile SDL_Surface *    destinationSurface,
int    xCoord,
int    yCoord,
int    tileNumber
 

Puts the tile specified onto the surface passed in.

Warning:
The surface onto which we are blitting should NOT be locked.
Parameters:
destinationSurface  The surface onto which we want to blit.
xCoord  The x coordinate of the anchor point of the tile to blit.
yCoord  The y coordinate of the anchor point of the tile to blit.
tileNumber  The number of the tile to blit. In the file, the numbers start with 0 (zero) and go from left to right, from top to bottom.

Definition at line 372 of file IsoTileSet.cpp.

References GetSDLRect, and OffsetRect.

Referenced by renderMap.

bool IsoTileSet::reloadTileset  
 

If the surface was lost, reloads it, but does not reparse the file.

Definition at line 298 of file IsoTileSet.cpp.

References ImageCanvas::loadImage.

bool IsoTileSet::unloadTileset  
 

Performs all the necessary clean-up operations.

Definition at line 321 of file IsoTileSet.cpp.

Referenced by loadTileset, and ~IsoTileSet.


The documentation for this class was generated from the following files:
Generated on Mon May 26 22:13:22 2003 for SDL Isometric Engine by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002