I recently starting to work on a tile based game on C++ using SFML library. Because I dont have much exprience with either C++ and SFML I'm pretty sute that the performance issue has something to do with my code.
The basic idea is that I have and 2d array of tiles which I create dynamicly this way:
Tile tiles**;
tiles = new Tile*[sizeX];
for(int i = 0; i < sizeX; i++)
tiles[i] = new Tile[sizeY];
And I draw everything this way:
for(int x = 0; x < sizeX; x++)
{
for(int y = 0; y < sizeY; y++)
{
tiles[x][y].Draw(app);
}
}
The variable app is sf::RenderWindow and it passes to the function as reference.
When I draw 10x10 map it runs on slow fps.
Sorry for my bad english!
Thanks in advance!
std::vector
instead. It's much easier to work with. For performance, make the underlying vector 1D, and wrap it in a 2DMatrix
class. - chris