Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Rein

Pages: [1]
1
General / Tilemap problem
« on: May 18, 2013, 06:34:57 pm »
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 );
        }
    }
}
 

Pages: [1]
anything