试图在我的XNA游戏中找出类的层次结构 [英] Trying to figure out the hierarchy of classes in my XNA game

查看:176
本文介绍了试图在我的XNA游戏中找出类的层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是一个新开发游戏在XNA和使用C#类,但我想开始一个半正式的游戏项目,我可以学习没有一次性的项目。

I am still kinda new to developing games in XNA and using classes with C#, but I want to start a semi-decent game project where I can learn without throwaway projects.

我想把我的游戏分成类。例如一个主游戏类,一个玩家类(我想要两个玩家,他们彼此战斗),一个级别类(用于绘制世界)和以后的东西,如上电类和网络类,所以我可以使一切多人。

I want to devide my game up into classes. For example a main game class, a player class (i want two players, and they battle against each other), a level class (for drawing the world) and maybe later on things like a power up class and a networking class so I can make everything multiplayer.

但我不知道在XNA游戏中开始使用这样的类的最好的方法。我做这样的类:

But I don't know the best way to start using classes like this in an XNA game. Do I make a class like this:

namespace MyGame
{
    class Player : MyGame
    {
        // whatever
    }
}

这个:

namespace MyGame
{
    class Player : Microsoft.Xna.Framework.Game
    {
        // whatever
    }
}



每个类都有 Initialize() Update() ()方法,我将使用spriteBatch和GraphicsDeviceManager从我的主游戏类传递给这些类...但我也不知道最好的方式传递他们,甚至如果我应该传递他们在类中自己创建新的。

I want each class to have something along the lines of Initialize(), Update() and Draw() methods, and I will use the spriteBatch and GraphicsDeviceManager from my main game class passed to these classes... but I also don't know the best way to pass them in, or even if I should be passing them in over making new ones in the classes themselves.

任何帮助是非常感谢。感谢。

Any help is greatly appreciated. Thanks.

推荐答案

你可能想要一个GameObjects层次结构,所以你的玩家和你的敌人等会有一个GameObject根。只有主游戏类实际上是从Microsoft.Xna.Framework.Game派生的。

You probably want to have a hierarchy of GameObjects, so you players and your enemies etc would have a GameObject as the root. Only the main Game class would actually be deriving from Microsoft.Xna.Framework.Game.

如果你遵循GameComponents的Xna模型,你会得到基本的GameObject DrawableGameComponent 。当然,玩家和敌人的逻辑可以提取出Controller类,然后你可以注入到GameObject中给每个对象它的游戏行为。

If you follow the Xna model of GameComponents, you would have the base GameObject deriving from DrawableGameComponent. Of course the logic of the players and enemies could be extracted out into Controller classes which you can then inject into the GameObject to give each object it's in game behaviors.

建议您先从 XNA创作者俱乐部开始使用一些游戏示例,但目前它已关闭,但我确信它将会很快。使用这些示例来帮助您制定游戏结构。

I would suggest you start with some of the game samples at XNA Creators Club, it's currently down but I am sure it will be up soon. Use these samples to help you formulate your game structure.

您可能还想查看 Riemer的XNA教程。这是一个相当不错的介绍。

You might also want to check out Riemer's XNA Tutorials. This is a quite a nice introduction.

这篇关于试图在我的XNA游戏中找出类的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆