gpt4 book ai didi

c# - 程序没有响应,调试显示 'Value cannot be null'

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:14 25 4
gpt4 key购买 nike

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/ .

谢谢!

最佳答案

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

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

关于c# - 程序没有响应,调试显示 'Value cannot be null',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41918174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com