我将以下代码作为我的XNA游戏的一部分:
private void gameOver() { if (!m_IsGameOver) { string message = String.Format("GAME OVER!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "GameOver", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } m_IsGameOver = true; } } private void gameWon() { string message = String.Format("You Won!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "You Won!", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } }出于某种原因,我收到以下错误:
"The name 'MessageBox' does not exist in the current context" "The name 'MessageBoxButtons' does not exist in the current context" "The name 'DialogResult' does not exist in the current context"我想添加“System.Windows ...”,但似乎“系统”中没有“窗口”......
我怎么解决这个问题?
I'm having the following code as part of my XNA game:
private void gameOver() { if (!m_IsGameOver) { string message = String.Format("GAME OVER!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "GameOver", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } m_IsGameOver = true; } } private void gameWon() { string message = String.Format("You Won!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "You Won!", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } }For some reason,I received the following errors:
"The name 'MessageBox' does not exist in the current context" "The name 'MessageBoxButtons' does not exist in the current context" "The name 'DialogResult' does not exist in the current context"I'm tring to add "System.Windows..." but it seems like that "System" does not have "windows" in it...
How can I solve this?
最满意答案
您似乎正在尝试在XNA中使用WinForms类。 但是,根据文档,WinForms不包含在XNA中:从MessageBox文档中可以看出,没有任何MessageBox方法在第一列中具有XNA徽标,这意味着XNA中不支持它们。 (相比之下,请参阅System.Linq.Enumerable上的文档 ,其中所有方法旁边都有X形XNA徽标)。
对于游戏内GUI,存在诸如此类的各种解决方案; 更多链接包含在此 , 此和此SO问题和此MSDN论坛发布包含另一个链接列表。
It seems that you are trying to use WinForms classes in XNA. However, according to the docs, WinForms is not included in XNA: As can be seen in the MessageBox docs, none of the MessageBox methods has the XNA logo in the first column, which means that none of them is supported in XNA. (See, for contrast, the docs on System.Linq.Enumerable, where all methods have the X-shaped XNA logo next to them).
For in-game GUIs, various solutions such as this one exist; more links are included in this, this and this SO question and this MSDN forum posting contains another list of links.
更多推荐
发布评论