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

Author Topic: [SFML1.6] Fading An Image In  (Read 2157 times)

0 Members and 1 Guest are viewing this topic.

Lith

  • Newbie
  • *
  • Posts: 5
    • View Profile
[SFML1.6] Fading An Image In
« 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:
Code: [Select]

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

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
[SFML1.6] Fading An Image In
« Reply #1 on: September 04, 2010, 05:44:50 pm »
Theoretically what you're doing should work. Is the image being displayed when you don't set the color?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SFML1.6] Fading An Image In
« Reply #2 on: September 04, 2010, 06:10:11 pm »
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.
Laurent Gomila - SFML developer

Lith

  • Newbie
  • *
  • Posts: 5
    • View Profile
[SFML1.6] Fading An Image In
« Reply #3 on: September 04, 2010, 06:23:25 pm »
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:
Code: [Select]

SomeClass(Image texture)
{
     TheSprite.SetImage(texture);
}

(Not Actual Code)


i changed it to something like this:
Code: [Select]

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?

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
[SFML1.6] Fading An Image In
« Reply #4 on: September 04, 2010, 06:39:34 pm »
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.