开发者

Why doesn't GraphicsHeight exist in my Game class?

开发者 https://www.devze.com 2023-03-28 03:22 出处:网络
I really need help on this so please be patient. Alright, so I\'ve recently started to work on my first game, very basic.

I really need help on this so please be patient.

Alright, so I've recently started to work on my first game, very basic.

I decided to create a GameObject class. That will contain the basics of my other classes (e.g : Player, Enemies).

So, this is the currently code of the GameObject class:

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 { re开发者_JS百科turn position.X; }
    }
    public float Y
    {
        set
        {
            position.Y = value;
        }
        get
        {
            return position.Y;
        }
    }
    public int GraphicsWidth { set; get; }
    public int GraphicsHeight { set; get; }
}

OK, so I wanted to set the GraphicsWidth and GraphicsHeight variables from the Main Class (Game1.cs) so in the Initialize method I've done this:

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

But it says that GraphicsHeight doesn't exist in the current context.

I know I'm missing something but I don't know what.

BTW, Is there anything wrong or anything that I can do better with my GameObject class?

Thanks a lot.


You must have another, concrete class inherit your abstract GameObject. For instance:

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

After instantiation, you will then be able to set those properties:

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

精彩评论

暂无评论...
验证码 换一张
取 消