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

Author Topic: Fading/Scale over time..  (Read 1800 times)

0 Members and 1 Guest are viewing this topic.

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Fading/Scale over time..
« on: February 23, 2013, 05:35:30 pm »
Okay I am trying to make an object fade over a certain time;

so say I want it to fade over 1 second, if I want to find out how much to remove each frame, whats the algorithm for it?

Alpha is 255 so say I want it to fade over 1 second I can do 1/255 to give me how much to subtract.. but my framerate is set to 60.. so only 60 frames are called a second not 255..

Cheers guys.
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Fading/Scale over time..
« Reply #1 on: February 23, 2013, 05:40:18 pm »
There is no "algorithm", it's simply division. You compute the ratio of the fading's progress in [0,1], and multiply it with 255.

By the way, if you don't want to reinvent the wheel, I have already implemented thor::FadeAnimation which can be applied to any class with setColor() and getColor() methods.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Fading/Scale over time..
« Reply #2 on: February 23, 2013, 05:51:41 pm »
Cheers Nexus.

so;

mSubtract = mLifeTime/255;

.....

loop{

mAlpha -= mLifeSubtract * 255;

}

 

Thats what your saying yeah? But there is only 60 frames in a second.. so this will only be called 60 times meaning it wont get all the way.. I am missing something
« Last Edit: February 23, 2013, 05:55:08 pm by Tally »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Fading/Scale over time..
« Reply #3 on: February 23, 2013, 06:16:35 pm »
Maybe:
m_Alpha=255-255*(nowtime-starttime)/(endtime-starttime);
Be careful to avoid pitfalls of integer division.
« Last Edit: February 23, 2013, 06:34:46 pm by FRex »
Back to C++ gamedev with SFML in May 2023