SFML community forums

Help => General => Topic started by: Kendoki on November 15, 2020, 02:28:14 pm

Title: Struggling to make a mapLoader function (Textures don't save)
Post by: Kendoki on November 15, 2020, 02:28:14 pm
Resolved thanks to thedaian
#0581
Title: Re: Struggling to make a mapLoader function (Textures don't save)
Post by: eXpl0it3r on November 15, 2020, 03:14:53 pm
It's the classic white square problem (https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#the-white-square-problem).

Your texture instance needs to exist as long as you're using it with a sprite. Since declared the textures in side the mapLoader function, the instances were being destroyed at the end of the function and the sprites pointed to non-existent textures.

I highly recommend to use something like at resource holder (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources/Include/Book).
Title: Re: Struggling to make a mapLoader function (Textures don't save)
Post by: Kendoki on November 15, 2020, 04:21:55 pm
It's the classic white square problem (https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#the-white-square-problem).

Your texture instance needs to exist as long as you're using it with a sprite. Since declared the textures in side the mapLoader function, the instances were being destroyed at the end of the function and the sprites pointed to non-existent textures.

I highly recommend to use something like at resource holder (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources/Include/Book).
Thanks you but the Textures are declared inside the main I do this to prevent it from being destroyed  but it still doesn't work (look at the 2nd code it's the correct version)