它一定很简单,我没有得到,但这是我的代码:
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();
}
...
现在在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();
}
我得到这个错误:
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
这是Player类:
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
我仍在学习C#,但它似乎来自Java,我不明白导致此问题的原因...
最佳答案
这意味着您Player
类不是公共的,并且在参数为Player
类型的公共类中声明了一个公共方法。
方法的可访问性不一致,因为有人可能会调用您的构造函数,因为它是公共的,但无法传递参数之一,因为不是。
关于c# - C#XNA的可访问性不一致,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7488184/