所以我试图在 XNA 4.0 win 游戏上制作一个文本框(不完全是一个文本框,只是改变一个 spriteFont 文本)继承我的代码:
usernameVar.Draw(spriteBatch, newInputText);
这将在每一帧绘制 newInputText 字符串
newInputText = username.update(mouse);
这将设置字符串,但这是我的问题
class Textbox
{
public Texture2D texture;
public Rectangle rectangle;
public bool isClicked;
public Textbox(Texture2D newTexture, Rectangle newRectangle)
{
texture = newTexture;
rectangle = newRectangle;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, rectangle, Color.White);
}
public String update(MouseState mouse)
{
Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);
var textboxText = new newText();
if (mouseRectangle.Intersects(rectangle))
{
isClicked = true;
if (isClicked)
{
textboxText.newtext = "a";
Connection.sendPacketBool("ae", textboxText.newtext);
return textboxText.newtext;
}
}
return null;
}
}
class newText
{
public String newtext
{
get
{
return this.newtext;
}
set
{
this.newtext = value;
}
}
}
这个 textbox.cs 文件首先给了我一些错误,我应该怎么做才能避免返回 IF 语句之外的内容?
public String update(MouseState mouse)
{
Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);
var textboxText = new newText();
if (mouseRectangle.Intersects(rectangle))
{
isClicked = true;
if (isClicked)
{
textboxText.newtext = "a";
Connection.sendPacketBool("ae", "a");
return "yo";
}
}
return null;
}
由于 return null 打破了我的文本框(我无法将 null 文本添加到 spritefont )另外,如果我删除 return null 添加 return "something" 我在设置属性上收到此错误
An unhandled exception of type 'System.StackOverflowException'
抱歉,我对 C# 和所有这些东西都很陌生,谢谢