SFML community forums
Help => Graphics => Topic started by: Lith on September 04, 2010, 04:54:56 pm
-
I have realised that this question has been asked many times but i think my variation is unique.
I can get the image to fade in perfectly, but it doesnt display the image, it just displays a white box.
I saw that the deafult color for an image is white (255,255,255,255). So i assumed that i can just change the last paramater and it would work.
What i think i am doing is filling in the image with a white rectangle by doing this:
BallSprite.SetColor(Color(255,255,255,0)); //the ball sprite will be completely transparent?
But thats not what i want to do, i just want to change it's alpha
-
Theoretically what you're doing should work. Is the image being displayed when you don't set the color?
-
A white sprite is often an indication that the image it uses doesn't exist anymore. For example, this may happen if you created it locally to a function.
-
I found out what the problem was.
I was trying to fade the image in inside a class and in this classes constructor, i was doing something like this:
SomeClass(Image texture)
{
TheSprite.SetImage(texture);
}
(Not Actual Code)
i changed it to something like this:
SomeClass(Image texture)
{
other_texture = texture;
TheSprite.SetImage(other_texture);
}
(Not Actual Code)
other_texture is declared in the .h file
i dont why it worked but it did, can anyone explain?
-
With the first code the image gets deleted after the function call, so it can't be drawn anymore. In the second code you are making a copy of the image, so the copy gets stored in the class and still can be drawn.