且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不知道如何解决这个问题***的例外是未处理的错误

更新时间:2022-06-20 10:50:11

确定 - 我看这个问题。

OK - I see the problem.

每当你创建一个 Player_Main - 它有它创建一个领域一个新的 Player_Sprite

Everytime you create a Player_Main - it has a field which creates a new Player_Sprite

Player_Sprite 本身具有这将创建另一个新的 Player_Main

Player_Sprite itself has a field which creates another new Player_Main,

这反过来又创造了新的 Player_Sprite 等,永远的(或至少直到你的堆栈溢出)

this in turn creates a new Player_Sprite etc, forever (or at least until your stack overflows)

修改

我猜你想要一个 Player_Main 这保留了 Player_Sprite 引用和 Player_Sprite 需要记住 Player_Main 创建它(而不是创建一个新的)。是这样的:

I'm guessing you want ONE Player_Main which retains a reference to Player_Sprite and that Player_Sprite needs to remember the Player_Main which created it (not create a new one). Something like:

public class Player_Main 
{
    public Player_Sprite psprite;

    public Player_Main()
    {
        psprite = new Player_Sprite(this);
    }
}

public class Player_Sprite 
{
    public Player_Main _pmain;

    public Player_Sprite(Player_Main pmain)
    {
        _pmain = pmain;
    }
}