Should I loop through tiles and delete each one? Or is there a better way?
if(tiles->at(i) != NULL) delete tiles->at(i);
std::vector<Tile*> tiles;
//TODO: need to fix this to match sprite sheet tiles size
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 32; x++) {
tiles.push_back((new Tile(x * 32, y * 32, 32, 32)));
}
}
class Tile {
public:
Tile(int left, int top, int w, int h);
Tile(int left, int top, int w, int h, bool solid);
virtual ~Tile();
bool isSolid();
sf::IntRect getTileRect();
private:
sf::IntRect tileRect;
bool solid;
};
#endif /* TILE_H */
#include "Tile.h"
Tile::Tile(int left, int top, int w, int h) {
tileRect.left = left;
tileRect.top = top;
tileRect.height = h;
tileRect.width = w;
solid = false;
}
Tile::Tile(int left, int top, int w, int h, bool solid) {
tileRect.left = left;
tileRect.top = top;
tileRect.height = h;
tileRect.width = w;
}
bool Tile::isSolid() {
return solid;
}
sf::IntRect Tile::getTileRect() {
return tileRect;
}
Tile::~Tile() {
}