Hi folks !
I'm using SFML since 2 days and I'm reading all official tutorials before doing any true project.
As a matter of practising, I've decided to improve the TileMap class of this
tutorial.
I want to load a Tilemap from a picture instead of a int[]. So I'm overloading the load method :
bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height); //Tutorial original method
bool load(const std::string& tileset, sf::Vector2u tileSize, const sf::Image &tiles, unsigned int width, unsigned int height); //My new method
Here is the implementation :
bool load(const std::string& tileset, sf::Vector2u tileSize, const sf::Image &tiles, unsigned int width, unsigned int height)
{
sf::Vector2u tailleImage = tiles.getSize();
int* tiles_num = new int[tailleImage.x * tailleImage.y];
for (int j = 0; j < tailleImage.y; j++)
{
for (int i = 0; i < tailleImage.x; i++)
{
tiles_num[i+j*tailleImage.x] = tiles.getPixel(i, j).r;
}
}
this->load(tileset, tileSize, tiles_num[], width, height);
bool ok = true;
delete tiles_num;
return ok;
}
When compiling I get two errors :
-Invalid use of "this" in non-member function
-expected primary-expression before ']' token.
I understand none of them...
Could someone help me ?
PS : If i use the same algorithm outside of the object, it works... I guess I've messed with pointers