SDL_Rect / Dynamic allocation question[solved]
Posted: Thu Jun 03, 2010 3:50 am
Not sure how to do this properly, or if it can be done, but I've seen it done a similar way in allegro, can tiles be dynamically created in this way using SDL_Rect? ( forgive my code ).
Or does this need to be done a completely different way?, such as this. ( it's a bit pseudo ).
Not so sure if it has to be done through a class, or if it can by dynamically allocated rects within the class, I'm actually just trying to make a tile grid that you can define at runtime ( enter in your variables, then it sets it up for tiles width/height/ and iterates through placing them ).
well, if you guys can shed any light thanks, in the meantime I'll keep working at it
Code: Select all
int amount;
SDL_Rect tile;
tile = new Tile[ amount ];
Code: Select all
// HEADER
//make a global pointer to the tile
extern class Tile *p_tile;
class Tile{
public:
Tile( int width, int height, int type, int layer )
~Tile()
private:
int layer;
int height;
int width;
int type;
SDL_Rect tile;
};
//CPP FILE
//init global pointer to NULL
Tile *p_tile = 0;
Tile::Tile( int width, int height, int type, int layer ){
p_tile = this;
}
int main(){
int x, y, z, a;
Tile *p_tile = new Tile( x, y, z, a );
}
//and delete of course
well, if you guys can shed any light thanks, in the meantime I'll keep working at it