Sign in to follow this  

Directx9 Fade in and out effect

This topic is 3595 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

This topic is 3595 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this