2011-08-13 11 views
1

私は本当にこれについて助けが必要なので、しばらくお待ちください。私のGameクラスにGraphicsHeightが存在しないのはなぜですか?

さて、私は最近、非常に基本的な、最初のゲームに取り組み始めました。

私はGameObjectクラスを作成することにしました。これには他のクラスの基礎が含まれます(例:Player, Enemies)。

だから、これはGameObjectクラスの現在のコードです:

abstract class GameObject 
{ 
    GraphicsDevice gr; 
    Vector2 position; 
    Texture2D texture; 
    public GameObject(Vector2 Position, Texture2D Texture) 
    { 
     this.position = Vector2.Zero; 
     this.texture = Texture; 
    } 
    public Vector2 Position { set; get; } 
    public Texture2D Texture { set; get; } 
    public float X 
    { 
     set { position.X = value; } 
     get { return position.X; } 
    } 
    public float Y 
    { 
     set 
     { 
      position.Y = value; 
     } 
     get 
     { 
      return position.Y; 
     } 
    } 
    public int GraphicsWidth { set; get; } 
    public int GraphicsHeight { set; get; } 
} 

OK、私はメインクラス(Game1.cs)からGraphicsWidthGraphicsHeight変数を設定したかったので、Initialize方法Iで

GraphicsHeight = graphics.PreferredBackBufferHeight; 
GraphicsWidth = graphics.PreferredBackBufferWidth; 

しかし、それはGraphicsHeightが現在のコンテキストに存在しないと言います。

私は何かが不足していることは知っていますが、何がわからないのですか。

私はGameObjectクラスで何か問題がありますか?

ありがとうございます。

答えて

0

抽象的なクラスを継承する別の具体クラスが必要です。GameObjectたとえば:インスタンス化した後

public class Player : GameObject 
{ 
    /* methods properties specific to player */ 
} 

、あなたはその後、これらのプロパティを設定することができるようになります:私はそれらに設定されたプロパティを入れています

Player.GraphicsHeight = graphics.PreferredBackBufferHeight; 
Player.GraphicsWidth = graphics.PreferredBackBufferWidth; 
+0

@labstract? – Joey

+0

あなたは答えることができますか?私はあなたの名前の綴り方を知らない。 – Joey

+2

このようなプロジェクトを掘り下げる前に、C#にもっと精通していなければならない。 – Sean

関連する問題