Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:07:18+00:00 2026-06-15T23:07:18+00:00

I changed my code but it still doesn’t work. I get this error message

  • 0

I changed my code but it still doesn’t work. I get this error message in the Intro class:
‘GameStates’: cannot reference a type through an expression; try ‘menuinterface.Game1.GameStates’ instead

What is wrong? I want to set the gamestate to MenuState if the player presses the Space Key.
Game1 class:

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    private IState currentState;

    public enum GameStates
    {
        IntroState = 0,
        MenuState = 1,
        MaingameState = 2,
    }

    public GameStates CurrentState
    {
        get { return currentGameState; }
        set { currentGameState = value; }
    }

    private GameStates currentGameState = GameStates.IntroState;


    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void Initialize()
    {
        currentState = new Intro(this);
        base.Initialize();
    }

    protected override void LoadContent()
    {       
        spriteBatch = new SpriteBatch(GraphicsDevice);
        currentState.Load(Content);
    }

    protected override void Update(GameTime gameTime)
    {
        currentState.Update(gameTime);     
        KeyboardState kbState = Keyboard.GetState();
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        currentState.Render(spriteBatch);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}

Interface:

public interface IState         
{ 
        void Load(ContentManager content); 
        void Update(GameTime gametime); 
        void Render(SpriteBatch batch); 
} 

Intro class:

public class Intro : IState
{
    private IState currentState;
    Texture2D Menuscreen;
    private Game1 game1;       

    public Intro(Game1 game)
    {
        game1 = game;
    }

    public void Load(ContentManager content)
    {
       Menuscreen = content.Load<Texture2D>("menu");
    }

    public void Update(GameTime gametime)
    {
        KeyboardState kbState = Keyboard.GetState();
        if (kbState.IsKeyDown(Keys.Space))
            game1.CurrentState = game1.GameStates.IntroState;
          currentState = new Menu(game1);
    }

    public void Render(SpriteBatch batch)
    {
        batch.Draw(Menuscreen, new Rectangle(0, 0, 1280, 720), Color.White);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:07:19+00:00Added an answer on June 15, 2026 at 11:07 pm

    Your problem is not understanding how enumerative types work. Specifically, this line:

    game1.GameStates = IntroState;
    

    First, let’s discuss a little of what an enum actually is. It’s a structure that simply assigns names to integer values, and can then refer to each value by name, and thus make code more readable (as it’s far easier to understand direction = Dir.Up than direction = 1).

    Notice how I use those two example statements, though. In the code, you treat the enum as a type not as a variable, and this is the problem you’re encountering. In fact, your problem is twofold. The first issue id that you’re trying to assign a value to a structure, which is similar to writing int = 4 – i.e. it doesn’t make sense. Your second issue is that enums are not global, so IntroState has no meaning outside game1.

    Interestingly enough, you’ve set up the system correctly, as you have the currentGameState variable, which is what you actually intend to change. However, it is a private variable, disallowing access to it from outside the game1 class. You can either make the variable public, or create a property to access it. The latter is good practice, as it allows you to control how the variable is set. To create this, you can use something like this:

    public GameStates CurrentState
    {
        get { return currentGameState; }
        set { currentGameState = value; }
    }
    

    Once you have this in your game1 class, you can set the game state like so:

    game1.CurrentState = Game1.GameStates.IntroState;
    

    Notice how this code tells the program where to look for what you want. IntroState is part of a structure (GameStates) within game1, and so needs to be accessed explicitly.

    Hopefully, this has helped you to understand how enumerative types work, and why the code you wrote doesn’t make sense, and thus why it breaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I changed the code and it still doesn't work! I used the links
This code was working earlier today, then randomly stopped, something must of changed, but
EDIT, Changed the code slightly based on answers below, but still haven't got it
I've changed my code completely. But active index is still showing problems. Sometimes it
I have changed a lot of things in a java code but now I
I have following code which works for radio buttons but need to be changed
I've changed from Git to SVN the folders which contains the project's code, but
I have a segmentation fault in the code below, but after I changed it
I have following asp.net code but it gives error when I change dropdown selected
I have this working code, but now i need to be able to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.