我试图通过让他们扩展Mircosoft.Xna.Framework.GameCompenent来封装我的游戏对象,然后仅构建它们并在Game1的Update()方法中管理它们.我有我的Game1类,Player类和Animation类.假设动画管理对象的Texture2D更改,在此实例中为Player.
我的问题是,即使我已经成功扩展了所有内容,没有语法错误,没有抛出异常,并且已经检查并重新检查了我编写的代码,否则不会调用覆盖函数,最终会出现黑屏.
Game1.cs :(注意改变的只有两行是Player声明)
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Player player;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
player = new Player(this);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{ …Run Code Online (Sandbox Code Playgroud)