1
Graphics / [Solved] Sprite Fade Out?
« on: September 29, 2011, 11:51:40 pm »
Ah thankyou for that. Ill see what i can do to get the same effect.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
bool fadeComplete = false;
if(GetElapsedTime() > 1.5f)
{
if(mAlpha < 250)
{
mAlpha += 10;
mSplashSprite->SetColor(sf::Color(255,255,255, mAlpha));
if( mAlpha == 250)
{
fadeComplete = true;
}
}
}
Im not sure you 're doing it the right way. The first snippet, unless running in a thread, shouldn't do an animation at all.
You're trying to evolve the alpha channel of the sprite in a single pass, while that won't allow anything to be displayed in-between the begining and ending state of the alpha animation. You need to do the alpha change over time.
That meaning each frame, before you render everything, you should call the update, and pass it the elapsed time since the last frame, and update only by that fraction of time.
The fade in and fade out are exactly the same thing, but inverted. Try to solve it on your own with this information
void SplashScene::Update(void)
{
// Check our App pointer
assert(NULL != engine && "SplashScene::Update() bad app pointer, init must be called first");
bool fadeComplete = false;
for(int a = 250; a > 0; a -= 5)
{
mSplashSprite->SetColor(sf::Color(255,255,255, a));
if( a == 250)
{
fadeComplete = true;
}
}
// Drop our state after 10 seconds have elapsed
if(fadeComplete == true && false == IsPaused() && GetElapsedTime() > 4.0f){
engine->mSceneManager.RemoveActiveState();
}
}
// Loop while IsRunning returns true
while(IsRunning() && mWindow.IsOpened() && !mSceneManager.IsEmpty())
{
// Get the currently active state
IState* scene = mSceneManager.GetActiveState();
// Check for corrupt state returned by our StateManager
assert(NULL != scene && "App::Loop() received a bad pointer");
// Create a fixed rate Update loop
while(anUpdateClock.GetElapsedTime() > anUpdateNext)
{
// Handle some events and let the current active state handle the rest
sf::Event anEvent;
while(mWindow.GetEvent(anEvent))
{
// Switch on Event Type
switch(anEvent.Type)
{
case sf::Event::Closed: // Window closed
Quit(StatusAppOK);
break;
case sf::Event::GainedFocus: // Window gained focus
scene->Resume();
break;
case sf::Event::LostFocus: // Window lost focus
scene->Pause();
break;
case sf::Event::Resized: // Window resized
break;
default: // Current active state will handle
scene->HandleEvents(anEvent);
} // switch(anEvent.Type)
} // while(mWindow.GetEvent(anEvent))
// Let the current active state perform updates next
scene->Update();
// Update our update next time
anUpdateNext += mUpdateRate;
} // while(anUpdateClock.GetElapsedTime() > anUpdateNext)
// Let the current active state draw stuff
scene->Draw();
// Display Render window to the screen
mWindow.Display();
// Handle Cleanup of any recently removed states at this point as needed
mSceneManager.HandleCleanup();
}