[HELP] Changing Screens in the Update() method?

Topics: Developer Forum
Dec 4, 2012 at 1:35 AM
Edited Dec 4, 2012 at 3:55 AM

I am having a problem changing screens from the update method because it lags.

This is the method I am calling always inside the update() method of my level:

private void CheckForGameFinished()
{
    if (this._balls.Count == 0)
    {
        ScreenManager.AddScreen(new Level2());
        ExitScreen();
        return;
    }
}

But it doesn't lag inside my OnCollision Method:

private bool OnCollision(Fixture self, Fixture other, Contact c)
{
    foreach(Ball b in this._balls)
    {
        if(other.Body == b._body)
        {
            Statics.PlayOwa(ScreenManager);
            b._body.Dispose();
            this._balls.Remove(b);
/////////////////////////////////////////////////////////
            this.CheckForGameFinished();
////////////////////////////////////////////////////////
            return true;
        }
    }

    return true;
}

private void CheckForGameFinished()
        {
            if (this._balls.Count == 0)
            {
                ScreenManager.AddScreen(new Level2());
                ExitScreen();
                return;
            }
        }
private void CheckForGameFinished()
{
    if (this._balls.Count == 0)
    {
        ScreenManager.AddScreen(new Level2());
        ExitScreen();
        return;
    }
}