Jump to content
  • Advertisement
Sign in to follow this  
hindmano

Directx9 Fade in and out effect

This topic is 3810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just FYI i finished my fade in and out effect and after several diffrent methods it seems that the best is to load a black image the same size as the screen resolution and then jun increment the Alpha here is a simple bit of code using c#
    //Global Variables  
    public int FadeState = 0;
    public int FadeAlpha = 0;


    void EffectsDoFade()
    {
        if (FadeState == 1)  // Fade out Fading in the black
        {
            if (FadeAlpha <= 255) FadeAlpha+=2;
            if (FadeAlpha >= 255)
            {
                FadeAlpha = 255;
                // Sit for x number of frames and show the loading screen
                //then fade back in 
                FadeState = 2;
            }
            else
            {
                // 0 alpha = clear 255 = opaque
                EKSprite.Draw(FadeScreen, Vector3.Empty, new Vector3(0, 0, 1f), Color.FromArgb(FadeAlpha, 255, 255, 255).ToArgb());
            }
        }
        if (FadeState == 2) //Fade back in  but fade out the black 
        {
            if (FadeAlpha >= 0) FadeAlpha-=2;
            if (FadeAlpha <= 0)
            {
                FadeAlpha = 0;
                //We are faded back in 
                // done 
                FadeState = 3;
            }
            else
            {
                // 0 alpha = clear 255 = opaque
                EKSprite.Draw(FadeScreen, Vector3.Empty, new Vector3(0, 0, 1f), Color.FromArgb(FadeAlpha, 255, 255, 255).ToArgb());
            }
        }
    }



all that is left is whatever event that you want to trigger the fade in and out sequence like a keypress just add a FadeState = 1; and make sure that EffectsDoFade(); is in your render loop between Sprite.Begin(), and Sprite.End() Wallah easy quick fade in and out and loots sharp to boot. if this helped you or you have questions please post here.

Share this post


Link to post
Share on other sites
Advertisement
Fantastic! That code sample should be able to help alot of new people getting into graphics/game programming a head start to do an introduction/open splash screen!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!