現在一定是很簡單的,我沒有得到,但這裏是我的代碼:C#XNA可訪問性不一致
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來了,我不明白是什麼原因造成這個問題...
好的,謝謝,我會閱讀。 – Alex