I am having an issue wherein private class members do not hold the value assigned to them in a member function.
I initialize the mMapWidth and mMapHeight values to 0, and then I update them to 5 in the load method. Shortly thereafter I call the draw method, but in the for tests mMapWidth and mMapHeight have a value of 0, and mMapCells is empty.
I assign the WorldMap object as follows:
main.h
WorldMap worldMap;
main.cpp
WorldMap worldMap(graphics, &camera, &textureTileset);
worldMap.load();
worldMap.draw();
The WorldMap object is declared and defined as follows:
worldmap.h
class WorldMap
{
public:
WorldMap();
WorldMap(Graphics*, Camera*, TextureManager*);
~WorldMap();
void draw();
void load();
private:
int mMapWidth = 0;
int mMapHeight = 0;
Graphics* pGraphics;
TextureManager* pTileSet;
Camera* pCamera;
};
worldmap.cpp
WorldMap::WorldMap(){}
WorldMap::WorldMap(Graphics* graphics, Camera* camera, TextureManager* tileset)
{
pGraphics = graphics;
pCamera = camera;
pTileSet = tileset;
mMapHeight = 0;
mMapWidth = 0;
}
WorldMap::~WorldMap(){}
void WorldMap::draw()
{
for (int tileY = 0; tileY < mMapHeight; ++tileY)
{
for (int tileX = 0; tileX < mMapWidth; ++tileX)
{
mMapCells[tileX + (tileY * mMapWidth)].draw();
}
}
}
void WorldMap::load()
{
mTileSize = 32;
mMapWidth = 5;
mMapHeight = 5;
mMapCells.reserve(mMapWidth * mMapHeight);
for (int tileY = 0; tileY < mMapHeight; ++tileY)
{
for (int tileX = 0; tileX < mMapWidth; ++tileX)
{
Cell* cell = new Cell();
cell->initialize(pGraphics, 32, 32, 5, pTileSet);
cell->setX(tileX * 32);
cell->setY(tileY * 32);
cell->setCurrentFrame(1);
mMapCells.push_back(*cell);
}
}
}
Thank you for your attention.