I would usually seek help on the XNA forums but they’re down at the moment, so I’ve come here.
I am making a new XNA game, and I want to have a player class. At the moment I have a main game class called Dots. This represents the main game. This is how my Player class is laid out at the moment:
namespace Dots
{
class Player : Microsoft.Xna.Framework.Game
{
Texture2D PlayerTexture;
Vector2 PlayerPosition;
public Player()
{
Content.RootDirectory = "Content";
PlayerTexture = Content.Load<Texture2D>("Player");
PlayerPosition = Vector2.Zero;
}
public void Update()
{
}
public void Draw(SpriteBatch SpriteBatch)
{
}
}
}
But I’m getting an error which I can’t work out how to solve. The error is:
Error loading “Player”. GraphicsDevice
component not found.
It’s throwing it at this line: PlayerTexture = Content.Load<Texture2D>("Player");.
I see in the main game class there is this line: Graphics = new GraphicsDeviceManager(this); but I have no idea what to do with it. Do I pass it to my Player class, or what?
Any help is appreciated, thanks.
UPDATE: This answer is apparently correct for older versions of XNA. See Andrew Russell’s answer for what’s being used currently.
Try overriding the LoadGraphicsContent method to load your content. As shown in this tutorial.