I am trying to do Lazy foo's tiling tutorial, and am having trouble following it, is there a better tutorial on this subject?
the problem I am having is understanding the following code.
I understand that it initialises the class creates a pointer of it, what I don't get is what is the array about?
class Tile
{
private:
//The attributes of the tile
SDL_Rect box;
//The tile type
int type;
public:
//Initializes the variables
Tile( int x, int y, int tileType );
//Shows the tile
void show();
//Get the tile type
int get_type();
//Get the collision box
SDL_Rect get_box();
Tile::Tile( int x, int y, int tileType )
{
//Get the offsets
box.x = x;
box.y = y;
//Set the collision box
box.w = TILE_WIDTH;
box.h = TILE_HEIGHT;
//Get the tile type
type = tileType;
}
};
Last edited by pythip on Mon May 03, 2010 10:30 am, edited 3 times in total.
so its just he made many instances of the class? the part that I was confused about was the initialisation process, I thought he was trying to pass an array though it.
pythip wrote:so its just he made many instances of the class? the part that I was confused about was the initialisation process, I thought he was trying to pass an array though it.
Ye, so in the code set_tiles( Tile *tiles[] ) an array of Tile pointers is passed, then in the loop if a tile type is recognized then the current tile the loop is on 't', will be initialized with new using the init constuctor Tile( int x, int y, int tileType ) else the file is invalid
//If the number is a valid tile number
if( ( tileType >= 0 ) && ( tileType < TILE_SPRITES ) )
{
tiles[ t ] = new Tile( x, y, tileType );
}
//If we don't recognize the tile type
else
{
//Stop loading map
map.close();
return false;
}