程序没有响应,调试说'值不能为空'

时间:2017-01-29 06:10:12

标签: c# xna monogame

using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Shooter
{
  class Player
   {
    //Animation representing player
    public Texture2D PlayerTexture;
    //Position of player relative to left side of screen
    public Vector2 Position;
    public bool playerActive;
    public int playerHealth;
    public int Width
    {
        get { return PlayerTexture.Width; }
    }

    public int Height
    {
        get { return PlayerTexture.Height; }
    }



    public void Initialize(Texture2D texture, Vector2 position)
    {
        PlayerTexture = texture;

        //sets the position of player to middle of the screen

        Position = position;

        playerActive = true;

        playerHealth = 100;


    }



    public void Update()
    {

    }


    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(PlayerTexture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
    }

}
}

这是我的代码,对于我的播放器类,程序没有编译错误。然而,当我运行游戏时,它表示" Game1已停止响应"当我调试时,会出现一条错误消息,指出" value不能为null"。我在这里使用XNA关注Windows游戏开发教程:

https://blogs.msdn.microsoft.com/tarawalker/2012/12/10/windows-8-game-development-using-c-xna-and-monogame-3-0-building-a-shooter-game-walkthrough-part-2-creating-the-shooterplayer-asset-of-the-game/

谢谢!

1 个答案:

答案 0 :(得分:0)

查看错误和您的代码我想这是您唯一的课程?如果是这样,您使用的教程有点奇怪。因为它绝对涵盖了初学者的素材,但它会跳过一些关键信息。

在monogame中,您的第一堂课应该始终从Game类继承。对于monogame / XNA游戏的基本结构,我建议你阅读以下文章:http://rbwhitaker.wikidot.com/monogame-project-template