0

XNA 4.0の勝利ゲームでテキストボックスを作成しようとしています(正確にはテキストボックスではなく、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 テキストをスプライトフォントに追加することはできません) また、return null を削除して return "something" を追加すると、set プロパティでこのエラーが発生します

An unhandled exception of type 'System.StackOverflowException'

申し訳ありませんが、私はC#とこれらすべてのものに非常に慣れていません。ありがとう

4

1 に答える 1