我是 XNA 的新手。我正在制作一个需要关卡编辑器的游戏。我需要一个文本框来获取关卡名称及其描述。所以我写了这样的代码:
if (isSaveBox)
{
KeyboardState ks = Keyboard.GetState();
Keys[] keys = ks.GetPressedKeys();
Keys tempKey = Keys.None;
foreach (Keys key in keys)
{
Keys currentKey = key;
if (ks.IsKeyUp(lastKey))
{
string toadd = key.ToString();
if (!(key == Keys.None) && key != Keys.Space && key != Keys.Back && key != Keys.Enter)
{
levelName += toadd;
}
else if (key == Keys.Space)
{
levelName += " ";
}
else if (key == Keys.Back)
{
levelName.Remove(levelName.Length - 1);
lastKey = currentKey;
}
}
if (currentKey != Keys.None && ks.IsKeyDown(currentKey))
{
tempKey = currentKey;
}
}
lastKey = tempKey;
message = "Save level" + "\n" + "Enter - yes / Esc - no" + "\n" + levelName;
但是当我尝试输入一些字母时,它们不会被添加到levelName
字符串中。有人可以帮我吗?