2017-01-29 9 views
2
using System; 

using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 

namespace Shooter 
{ 
    class Player 
    { 
    //Animation representing player 
    public Texture2D PlayerTexture; 
    //Position of player relative to left side of screen 
    public Vector2 Position; 
    public bool playerActive; 
    public int playerHealth; 
    public int Width 
    { 
     get { return PlayerTexture.Width; } 
    } 

    public int Height 
    { 
     get { return PlayerTexture.Height; } 
    } 



    public void Initialize(Texture2D texture, Vector2 position) 
    { 
     PlayerTexture = texture; 

     //sets the position of player to middle of the screen 

     Position = position; 

     playerActive = true; 

     playerHealth = 100; 


    } 



    public void Update() 
    { 

    } 


    public void Draw(SpriteBatch spriteBatch) 
    { 
     spriteBatch.Draw(PlayerTexture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); 
    } 

} 
} 

これは私のプレーヤークラスのコードであり、プログラムにはコンパイルエラーがありません。しかし、ゲームを実行すると、「Game1が応答を停止しました」と表示され、デバッグすると、「値はnullにできません」というエラーメッセージが表示されます。 XNAを使用したWindowsゲーム開発のチュートリアルには、ここをクリックしています:プログラムが応答していない、デバッグに '値はnullにできません'と表示されます。

https://blogs.msdn.microsoft.com/tarawalker/2012/12/10/windows-8-game-development-using-c-xna-and-monogame-3-0-building-a-shooter-game-walkthrough-part-2-creating-the-shooterplayer-asset-of-the-game/

ありがとうございます!

答えて

0

エラーとコードを見れば、これはあなたの唯一のクラスだと思いますか?もしそうなら、使用しているチュートリアルはちょっと変わっています。それは間違いなく初心者のマテリアルをカバーしますが、いくつかの重要な情報はスキップします。

モノゲームでは、最初のクラスは常にGameクラスから継承する必要があります。モノゲーム/ XNAでのゲームの基本的な構造については、次の記事を読むようアドバイスします:http://rbwhitaker.wikidot.com/monogame-project-template

関連する問題