2017-01-29 1 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

관련 문제