C# XNA inconsistent accessibility
It must be something pretty simple that i didn't get, but here's my code:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
WorldManager worldManager;
Player m_player = new Player(new Point(30, 15));
protected override void Initialize()
{
worldManager = new WorldManager(this, m_player);
Components.Add(worldManager);
base.Initialize();
}
...
Now in WorldManage:
public class WorldManager : Microsoft.Xna.Framework.DrawableGameComponent
{
SpriteBatch spriteBatch;
//UserControlledTile player;
Player player;
List<Tile> tileList = new List<Tile>();
World world;
SpriteFont testFont;
public WorldManager(Game game, Player player)
: base(game)
{
this.player = player;
world = new World();
}
开发者_如何学PythonAnd i get this error:
Error 1 Inconsistent accessibility: parameter type 'WindowsGame2.Player' is less accessible than method 'WindowsGame2.WorldManager.WorldManager(Microsoft.Xna.Framework.Game, WindowsGame2.Player)' D:\dropbox\Dropbox\Projects\WindowsGame2\WindowsGame2\WindowsGame2\WorldManager.cs 28 16 WindowsGame2
Here's the Player class:
class Player : Character
{
public Player(Point startLoc)
{
base.Position = startLoc;
base.CharacterTile = new UserControlledTile(new Point(20, 15), Color.Yellow, "X");
base.Name = "Hero";
base.Attack = 1;
base.Defense = 1;
base.HP = 20;
base.Level = 1;
} //end constructor
public override void Update(GameTime gameTime)
{
//player has already moved
if (hasMoved)
{
prevGameTime += gameTime.ElapsedGameTime.Milliseconds;
if (prevGameTime > timeBetweenMove)
{
hasMoved = false;
prevGameTime = 0;
}
return;
}
KeyboardState keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.Left))
{
m_position.X--;
hasMoved = true;
}
else if (keyboardState.IsKeyDown(Keys.Right))
{
m_position.X++;
hasMoved = true;
}
else if (keyboardState.IsKeyDown(Keys.Up))
{
m_position.Y--;
hasMoved = true;
}
else if (keyboardState.IsKeyDown(Keys.Down))
{
m_position.Y++;
hasMoved = true;
}
if (m_position.X < 0)
m_position.X = 0;
if (m_position.X > 56)
m_position.X = 56;
if (m_position.Y < 0)
m_position.Y = 0;
if (m_position.Y > 32)
m_position.Y = 32;
m_CharacterTile.Update(gameTime, m_position);
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, SpriteFont font)
{
m_CharacterTile.Draw(gameTime, spriteBatch, font);
}
}//end class
I'm still learning C#, but it seems coming from Java, i don't get what is causing this problem...
This means that you Player
class is not public, and you declared a public method in a public class that has a parameter of type Player
.
The method accessibility is inconsistent because someone might call your constructor, because it is public, but could not pass one of the parameters, because it is not.
unfortunately you don't show the code for Player, but it is likely that you have defined it as internal, while the WorldManager and its constructor is public.
Please read and understand Access Modifiers
精彩评论