Hi all,
I'm new to SFML and C++ in general. I've been trying to make a tilemap for a simple game, but so far without success.
Below is the class so far. (which is not a lot) My code compiles, until it reaches the draw method. There I get "Thread 1: EXC_BAD_ACCESS (code=13, address=0x0)".
I guess that would mean the pointer to the tile is not available anymore, but I don't see why...I just added those tiles...
Any help is welcome for this beginner.
Thank you!
#include "Includes.h";
#include "Tile.h";
#ifndef Monstrum_TileMap_h
#define Monstrum_TileMap_h
class TileMap
{
public:
TileMap();
~TileMap();
int mWidth;
int mHeight;
void addTile(int x, int y, Tile* tile);
Tile* getTile( int x, int y );
void draw( sf::RenderWindow& renderWindow );
bool create( int width, int height );
std::vector<std::vector<Tile*> > mTiles;
};
#endif
#include "Includes.h"
#include "TileMap.h"
TileMap::TileMap()
{
}
TileMap::~TileMap()
{
}
bool TileMap::create( int width, int height)
{
mWidth = width;
mHeight = height;
mTiles.resize( width );
for(int i = 0; i < width; i++)
{
mTiles.at(i).resize( height, 0 );
}
Tile* tile;
for ( int i = 0; i < width; ++i )
{
for ( int j = 0; j < height; ++j )
{
addTile( i, j, tile );
}
}
return true;
}
void TileMap::addTile( int x, int y, Tile* tile )
{
mTiles[x][y] = tile;
}
Tile* TileMap::getTile(int x, int y)
{
return mTiles[x][y];
}
void TileMap::draw( sf::RenderWindow& renderWindow )
{
for( int x = 0; x<mWidth; x++) {
for( int y = 0; y<mHeight; y++) {
getTile( x, y )->draw( renderWindow );
}
}
}