Page 1 of 1

[solved] lazy foo tiling trouble

Posted: Sun May 02, 2010 10:36 pm
by pythip
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?

Code: Select all

Tile *tiles [TOTAL_TILES];
Tile class

Code: Select all

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;

}


};

Re: lazy foo tiling trouble

Posted: Sun May 02, 2010 11:22 pm
by davidthefat
A map is not just a single tile, you need more than one tile, hence explaining the array

Re: lazy foo tiling trouble

Posted: Mon May 03, 2010 7:37 am
by pythip
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.

Re: lazy foo tiling trouble

Posted: Mon May 03, 2010 9:09 am
by GroundUpEngine
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 ;)

snippet from set_tiles() ->

Code: Select all

//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;
}

Re: lazy foo tiling trouble

Posted: Mon May 03, 2010 10:28 am
by pythip
oh, I get it now, thanks for the help

Re: [solved] lazy foo tiling trouble

Posted: Mon May 03, 2010 2:34 pm
by GroundUpEngine
No prob :)