Jump to content
  • Advertisement
Sign in to follow this  
ReDespawn

Object reference not set to an instance of an object.

This topic is 2583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am getting the error "Object reference not set to an instance of an object." when I'm trying to run my XNA game. I'm basicly trying to sort-of make an engine so I load in textures using a class and manage all the sprites with another class.

Here's my code:
Game.cs:

ContentManager contentManager;

Sprite character;
SpriteManager spriteManager;

public Game()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

protected override void Initialize()
{
character = new Sprite();
spriteManager = new SpriteManager();

base.Initialize();
}

protected override void LoadContent()
{
character.setTexture(spriteManager.loadTexture(contentManager, "CharSprite"));
character.setPosition(new Vector2(50, 50));

spriteBatch = new SpriteBatch(GraphicsDevice);
}


Sprite.cs

private Texture2D texture;

public void setTexture(Texture2D spriteTexture)
{
texture = spriteTexture;
}


SpriteManager.cs

private Texture2D loadedTexture;

public Texture2D loadTexture(ContentManager cm, string asset)
{
loadedTexture = cm.Load<Texture2D>(asset);
return loadedTexture;
}


(This is a simplified version so you don't have to look through 150 lines of code)

What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!