I have a class GameServices which contains an instance of the class GameStates.
The class GameStates has a public enum called GameState and a static var named CurrentGameState.
My problems is, I can access CurrentGameState from the GameStates class, but not the GameState enum it self, while it is public.
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using SpaceGame.UI;
using SpaceGame.Content;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace SpaceGame.Game
{
public class GameServices
{
public static ContentLoader ContentLoaderService;
public static UIHandler UIHandlerService;
public static GameStates GameStatesService;
public static void Initialize(ContentManager contentManager, GraphicsDevice graphicsDevice)
{
ContentLoaderService = new ContentLoader(contentManager);
UIHandlerService = new UIHandler(graphicsDevice);
GameStatesService = new GameStates();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SpaceGame.Game
{
public class GameStates
{
public GameState CurrentGameState { get; set; }
public enum GameState
{
Settings,
Splash,
SpaceShipyard
}
public GameStates()
{
CurrentGameState = GameState.Splash;
}
}
}
Am I doing something wrong?
Thanks in Advance,
Mark
You should be able to access it. Since you've defined it inside the GameStates
class, then the full name of the type will be:
SpaceGame.Game.GameStates.GameState
If that still isn't resolving, then you could have namespace issues, this should always work:
global::SpaceGame.Game.GameStates.GameState
IF you're trying to access it from the same namespace, you'll have to do something like
GameStates.GameState state = GameStates.GameState.Settings
If you're doing that, but it's not working than I can't help you at this point.
Here's a sample that i did. It compiles for me.
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
A.AEnum a = A.AEnum.a;
}
}
public class A
{
public enum AEnum
{
a,b
}
}
}
Basically, don't use enums (or classes for that matter) inside other classes. There are many complications when using them.
Also, CurrentGameState isn't static (at least in the code you provided), and you said it should be, so changing it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.