2017-04-15 13 views
0

このクラスで何が間違っていますか?モノゲームとC#を使用していますが、オブジェクトはプログラムでレンダリングされません。私はこのMonogameクラスで何が間違っていますか?

class Player : Game 
    { 
     Texture2D PlayerSprite; 
     Vector2 PlayerPosition; 


     public Player() 
     { 
      Content.RootDirectory = "Content"; 
      PlayerSprite = Content.Load<Texture2D>("spr_Player"); 
      PlayerPosition = Vector2.Zero; 
     } 

     public void Update() 
     { 


     } 

     public void Draw(SpriteBatch SpriteBatch) 
     { 
      SpriteBatch.Begin(); 
      SpriteBatch.Draw(PlayerSprite,PlayerPosition, new Rectangle(0, 0, 32,32), Color.White); 
      SpriteBatch.End(); 
     } 
    } 
+0

は、あなたがエラーを取得するのですか? – CodingYoshi

+0

エラーなし、コンパイル時にオブジェクトが表示されません。それはGame1クラスの別のものを参照するべきであるというプレーヤーと呼ばれる別のクラスにありますか? –

+0

@Liam Earle、どこにプレーヤーを作りますか? – vyrp

答えて

0
  • ロード、更新、および描画方法は継承されたゲームのクラスに属し、それによってオーバーライドされます。
  • また、SpriteBacthオブジェクトを開始する必要があります。
  • GraphicsDeviceオブジェクトはGameメインクラスに存在します。

これを試してみてください:

class Player : Game 
{ 
    Texture2D PlayerSprite; 
    Vector2 PlayerPosition; 
    SpriteBatch spriteBatch; 

    public Player() 
    { 
     Content.RootDirectory = "Content"; 
     PlayerSprite = Content.Load<Texture2D>("spr_Player"); 
     PlayerPosition = Vector2.Zero; 
    } 

    protected override void LoadContent() 
    { 
     spriteBatch = new SpriteBatch(GraphicsDevice); 
    } 

    protected override void Update(GameTime gameTime) 
    { 
    } 

    protected override void Draw(GameTime gameTime) 
    { 
     spriteBatch.Begin(); 
     spriteBatch.Draw(PlayerSprite,PlayerPosition, new Rectangle(0, 0, 32,32), Color.White); 
     spriteBatch.End(); 
    } 
} 
関連する問題