Hi guys !
I have been playing around with the tilemap class (
http://www.sfml-dev.org/tutorials/2.3/graphics-vertex-array.php#example-tile-map ), and everything is working fine : I can display 2 'test' layers in one of the viewports I set up.
I next wanted to display the tileset texture that was loaded inside the tilemap class in a second viewport. But here, I ran into trouble and I don't understand why ...
class TileMap : public sf::Drawable, public sf::Transformable {
public:
bool load() {
if (!texTileSet.loadFromFile("maps/newTileSet.png")) {
return false;
}
//...
}
sf::Texture getTileSet() { //THIS IS NOT WORKING
return texTileSet;
}
//...
private:
sf::Texture texTileSet;
//...
}
Main.cpp
int main() {
//...
TileMap tileMap;
if (!tileMap.load()) {
return -1;
}
sf::Sprite sprite;
sprite.setTexture(tileMap.getTileSet());
window.draw(sprite);
//...
}
The result of this code : "not_ok.png" (no errors or crashes).
On the other hand, if I reload the texture inside main, all is fine.
Main.cpp
int main() {
//...
TileMap tileMap;
if (!tileMap.load()) {
return -1;
}
sf::Texture texTileSet;
if (!texTileSet.loadFromFile("maps/newTileSet.png")) { //THIS IS OK
return false;
}
sf::Sprite sprite;
sprite.setTexture(tileMap.getTileSet());
window.draw(sprite);
//...
}
The result of this code : "ok.png".
What am I doing wrong here ?
Thanks !