I'm making a game and I've run into a bit of a snag. From prior research I found a way of altering a variable from multiple classes, but it isn't working. I have set all my screens into an array list and i'm trying to use this variable to change between the screens, but the screen is not changing. there is no error showing up in visual studio, so i'm clueless as to what went wrong. sorry for not being able to point out a certain line. any help is very much appreciated.
this is the class that uses the Int32 GlobalVar.activescreen
public class ManageTheseScreens
{
ArrayList Screens;
Screen CurrentScreen;
public ManageTheseScreens()
{
Screens = new ArrayList();
Screens.Add(new TitleScreen());
Screens.Add(new OptionScreen());
CurrentScreen = (Screen)Screens[GlobalVar.activescreen];
}
public void Draw(SpriteBatch spriteBatch)
{
CurrentScreen.Draw(spriteBatch);
}
}
this is the class that holds the Int32
public static class GlobalVar
{
public static Int32 activescreen = 0;
}
this is the class that is trying to change it
class OptionScreen : Screen
{
Rectangle titleButton1Rectangle = new Rectangle(450, 100, 222, 44);
MouseState mouseState;
public OptionScreen()
: base()
{
}
public void Update()
{
mouseState = Mouse.GetState();
if (titleButton1Rectangle.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y)))
{
if (Mouse.GetState().RightButton == ButtonState.Pressed)
{
///this should switch screens
GlobalVar.activescreen = 1;
}
}
}