SFML community forums

Help => Graphics => Topic started by: MrSnappingTurtle on December 03, 2014, 04:50:34 am

Title: Help with white texture sprite issue
Post by: MrSnappingTurtle 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:
(http://puu.sh/deWC9/2ae972a260.jpg)

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!
Title: Re: Help with white texture sprite issue
Post by: eXpl0it3r 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 (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources).
Title: Re: Help with white texture sprite issue
Post by: MrSnappingTurtle 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 (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources).

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!