У меня проблема с NullReferenceException в XNA. У меня 4 класса: Hero, Sprite, Fireball, Game1. Через отладку я вижу, что проблема возникает после моих Fireball загрузки содержимого через трубуNullReferenceException в ContentManager, XNA
class Fireball: Sprite
{
const int MAX_DISTANCE = 500;
public bool Visible = false;
Vector2 mStartPosition;
Vector2 mSpeed;
Vector2 mDirection;
public void LoadContent(ContentManager theContentManager)
{
base.LoadContent(theContentManager, "Fireball");
Scale = 0.3f;
}
Тогда в моем классе Sprite я пытаюсь загрузить через ContentManager моей текстуре
class Sprite
{
//The asset name for the Sprite's Texture
public string AssetName;
//The Size of the Sprite (with scale applied)
public Rectangle Size;
//The amount to increase/decrease the size of the original sprite.
private float mScale = 1.0f;
//The current position of the Sprite
public Vector2 Position = new Vector2(0, 0);
//The texture object used when drawing the sprite
private Texture2D myTexture;
//Load the texture for the sprite using the Content Pipeline
public void LoadContent(ContentManager theContentManager, string theAssetName)
{
myTexture = theContentManager.Load<Texture2D>(theAssetName);
AssetName = theAssetName;
Source = new Rectangle(0, 0, myTexture.Width, myTexture.Height);
Size = new Rectangle(0, 0, (int)(myTexture.Width * Scale), (int)(myTexture.Height * Scale)); ;
}
И это дает мне NullReferenceException в myTexture = theContentManager.Load (theAssetName); линия. Через отчет отладки я вижу, что имя актива имеет в нем «Fireball», но сам ContentManager получает значение null. Что я делаю не так? Поскольку я новичок в C#, я был бы признателен, если кто-нибудь может сказать мне, какие строки я должен добавить и где. Если кому-то нужен полный проект, он здесь https://www.dropbox.com/s/1e353e834rggj40/test.rar Так как он немного массивный.
Я управлял полным проектом, и он отлично работал – Cyral
Я забыл добавить! Загрузка текстуры Fireball происходит только при нажатии правой клавиши Ctrl. Попробуй. – metamorphling