【问题标题】:Program is not responding, debugging says 'Value cannot be null'程序没有响应,调试说“值不能为空”
【发布时间】:2017-01-29 06:10:11
【问题描述】:
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 已停止响应”,当我调试时,出现一条错误消息,提示“值不能为空”。我在这里学习使用 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/.

谢谢!

【问题讨论】:

    标签: c# xna monogame


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 2017-07-13
      相关资源
      最近更新 更多