Player class with my C # game

I usually turn to the XNA forums for help, but now they do not work, so I came 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 is the main game. This is how my class is Playerpresented 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 get an error that I cannot solve, how to solve it. Error:

Error loading "Player". GraphicsDevice component not found.

He throws it on this line: PlayerTexture = Content.Load<Texture2D>("Player");.

In the main class of the game, I see this line: Graphics = new GraphicsDeviceManager(this);but I have no idea what to do with it. Am I passing it on to the class Playeror what?

Any help is appreciated, thanks.

+5
5

UPDATE: , -, XNA. . Andrew Russell , .

LoadGraphicsContent . .

    protected override void LoadGraphicsContent(bool loadAllContent)
    {
        if (loadAllContent)
        {
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            // TODO: Load any ResourceManagementMode.Automatic content
            t2dMap = content.Load<Texture2D>(@"content\textures\map_display");
            t2dColorKey = content.Load<Texture2D>(@"content\textures\map_colorkey");
        }
        // TODO: Load any ResourceManagementMode.Manual content
    }
+2

, ( ). ( ) , .

:

, , . , LoadContent Microsoft.Xna.Framework.Game. :

. , , , , DeviceReset. GraphicsDevice , LoadContent.

, :

protected override void LoadContent()
{
    PlayerTexture = Content.Load<Texture2D>("Player");
    PlayerPosition = Vector2.Zero;
    base.LoadContent();
}

, ( ). , , .

, , Draw Update , XNA.

:. , , XNA Game. "Player", , .

"Player", , .

, .

+6

XNA Intellisense . , Texture2D Rectangle, , "Resolve", "" - , . , . , , , .

+1

, :

  • , Build Action Compile
  • .spritefont ( )
  • , LoadContent
0

, .

.

"".

"Hi Def"... "Reach".

.

-2

All Articles