0

I'm currently working on making an XNA 2D platformer, and I'm wondering if it's possible to draw a kind of static GUI over the game?

What i mean here is that while the game updates and the players position changes etc, the GUI would be drawn on a kind of static layer (overlay?), that would be the size of the window the game is being run in. That way the game wouldn't have to constantly update the GUI's position and thus be a little bit nicer to handle.

Any ideas?

Thanks for your time

4

2 回答 2

0

是的,你可以使用 spritebatch 来绘制它们 :)

//HudTexture is a transparent texture the size of the window/screen, with hud drawn onto it.
SpriteBatch.Draw(HudTexture, Vector2.Zero, Color.White);
//Let's say that it works well to draw your score at [100,100].
SpriteBatch.DrawString(HudFont, Points.ToString(), new Vector2(100,100), Color.White);

如果您打算制作更多 GUI(按钮等),您可能想查看我写给另一篇文章的这个答案: XNA DrawString() draws only a partial string

还; 对于绘图分数等,由于 ToString,我经历了相当多的装箱/拆箱。出于这个原因,我经常有一个字符串数组来表示分数:

String[] ScoreText = new String[100000]; //As big as your max score

//In Initializing method:
for (int i = 0; i < ScoreText.Length; i++)
    ScoreText[i] = i.ToString();

//In draw:
SpriteBatch.DrawString(HudFont, ScoreText[Points], new Vector2(100,100), Color.White);
于 2013-04-18T10:39:31.900 回答
0

SpriteBatch当然,您可以使用例如在任何您想要的地方绘制任何精灵。

你如何管理它取决于你。只是不要给出任何转换矩阵,事物将在您指定的坐标处绘制。

你最终会绘制你的关卡(例如,它会被一些相机位置偏移),然后在上面绘制你的 GUI 元素,没有偏移。

于 2013-04-18T09:42:18.533 回答