2011-08-13 2 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; } 
} 

확인, 그래서 메인 클래스 (은 Game1.cs)에서 GraphicsWidthGraphicsHeight 변수를 설정하고 싶은 Initialize 방법 그래서 이 작업을 수행했습니다 :

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

그러나 GraphicsHeight은 현재 컨텍스트에 존재하지 않습니다.

나는 뭔가를 놓친다는 것을 알고 있지만 나는 무엇을 모른다.

현재, 내 GameObject 클래스로 더 좋은 점이 있습니까?

고마워요.

답변

0

추상화 된 다른 구체적인 클래스가 있어야합니다. GameObject. 예를 들면 : 나는에서 그 속성 설정을 걸었습니다

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

@labstract : 인스턴스 후

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

, 당신은 그 때 그 속성을 설정할 수 있습니까? – Joey

+0

대답 해 주시겠습니까? 나는 당신의 이름을 철자하는 법을 모른다. – Joey

+2

이런 프로젝트를 탐구하기 전에 C#에 익숙해 져야한다. – Sean

관련 문제