Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Struggling to make a mapLoader function (Textures don't save)  (Read 1186 times)

0 Members and 1 Guest are viewing this topic.

Kendoki

  • Newbie
  • *
  • Posts: 2
    • View Profile
Struggling to make a mapLoader function (Textures don't save)
« on: November 15, 2020, 02:28:14 pm »
Resolved thanks to thedaian
#0581
« Last Edit: November 15, 2020, 06:03:21 pm by Kendoki »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Struggling to make a mapLoader function (Textures don't save)
« Reply #1 on: November 15, 2020, 03:14:53 pm »
It's the classic 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kendoki

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Struggling to make a mapLoader function (Textures don't save)
« Reply #2 on: November 15, 2020, 04:21:55 pm »
It's the classic 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.
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)

 

anything