• Advertisement
Sign in to follow this  

Menu Fading

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

Hey everybody!

So I'm working on my own Snake clone using C# and XNA, and I created a very simple state manager to cycle through the menu and game states. I know, I know, "why re-invent the wheel? why not use the GameStateManagement sample?". Honestly, I'm having trouble understanding their code, and need more time to digest it. I don't need a fancy menu or state manager, just the very basics so that I can create a game.

Moving on! I'm trying to add a fade effect to my splash screen. Essentially, I want the screen to slowly become black, and then after five game seconds, switch to the Main Menu state. Unfortunately, when I try to increase the transparency so that it goes from white to black, it just leaves fills in the entire background with a black screen (almost like the new Color(255, 255, 255, fadeValue) argument isn't being called). Here's the source code:

Splash.cs
[source lang="csharp"]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Snake
{
static class Splash
{
#region FIELDS

// These are the splash screen's data fields.
private static Texture2D texture;
private static Rectangle position;
private static Texture2D spacer;

private static int fadeValue = 1;

#endregion

#region METHODS

/// <summary>
/// The LoadContent(Content) method will load the default content into memory.
/// </summary>
/// <param name="Content"></param>
public static void LoadContent(ContentManager Content)
{
// Load the texture for later use.
texture = Content.Load<Texture2D>("Screens/Splash");
spacer = Content.Load<Texture2D>("Spacer");

// Create a default position for the splash screen.
position = new Rectangle(0, 0, 800, 600);
}

/// <summary>
/// The Update(gameTime) method will be called each frame and handles all game logic.
/// </summary>
/// <param name="gameTime"></param>
public static void Update(GameTime gameTime)
{
// If the total GameTime (since the program started) has gone over a second, or a key is pressed, change the game state.
if (gameTime.TotalGameTime.TotalSeconds >= 5 || InputManager.AnyKeyPressed())
{
ScreenManager.State = MenuState.MainMenu;
}


if(fadeValue < 255)
fadeValue += 1;
}

/// <summary>
/// The Draw(spriteBatch) method will be called each frame and handles the drawing logic.
/// </summary>
/// <param name="spriteBatch"></param>
public static void Draw(SpriteBatch spriteBatch)
{
// Create a new SpriteBatch to avoid overwriting layers.
spriteBatch.Begin();

// Draw the splash screen to our buffer.
spriteBatch.Draw(spacer, new Rectangle(0, 0, 800, 600), new Color(255, 255, 255, 200));
spriteBatch.Draw(texture, position, new Color(255, 255, 255, fadeValue));

// End the SpriteBatch object.
spriteBatch.End();
}

#endregion
}
}
[/source]

Share this post


Link to post
Share on other sites
Advertisement
Hahahaha. After I reviewed my post on here, I managed to find the problem. I was setting the new Color when I drew the actual MainMenu texture, not on my black rectangle. Working now. Thank you!

Share this post


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

  • Advertisement