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

Author Topic: Help with white texture sprite issue  (Read 2031 times)

0 Members and 1 Guest are viewing this topic.

MrSnappingTurtle

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Help with white texture sprite issue
« on: December 03, 2014, 04:50:34 am »
Hi, I am trying to draw certain sprites, but they end up being drawn as white squares or even distorted. Everything that has been drawn as a white rectangle follows the following format:

Object
-Texture
-Sprite

Then the level has a list of objects.

It then returns the list by copy to the engine which draws it.

Here is the code for the trees:
http://pastebin.com/UmsapXJj

The end result:


Other items are having the same issue such as the gun. The tiles aren't and they are the only ones stored in a regular array. Could that have something to do with it?

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Help with white texture sprite issue
« Reply #1 on: December 03, 2014, 08:10:55 am »
What should the white squares represent?

Also have you read this:
http://sfml-dev.org/tutorials/2.1/graphics-sprite.php#the-white-square-problem
https://github.com/SFML/SFML/wiki/FAQ#graphics-white-rect

It's a rather bad idea to let your tree object hold the texture and this also most likely the origin of your problem, because once you push_back the tree, you're creating a copy of the tree, thus the texture reference will be lost and you get a white square.
Instead you should manager your resources outside of the class, for example with a resource holder.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrSnappingTurtle

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Help with white texture sprite issue
« Reply #2 on: December 05, 2014, 05:20:30 am »
What should the white squares represent?

Also have you read this:
http://sfml-dev.org/tutorials/2.1/graphics-sprite.php#the-white-square-problem
https://github.com/SFML/SFML/wiki/FAQ#graphics-white-rect

It's a rather bad idea to let your tree object hold the texture and this also most likely the origin of your problem, because once you push_back the tree, you're creating a copy of the tree, thus the texture reference will be lost and you get a white square.
Instead you should manager your resources outside of the class, for example with a resource holder.

Thanks man, it now hold a pointer to a texture inside an ImageManager class. That way when it's copied it still points to the same place. Thanks again!