0
votes

We are currently optimizing our first XNA game, we ran in into a problem:

There is a ScreenManager which manages all the screens. Every time we 'push' a new screen we remove (null) the old screen, so graphics should be removed from the memory. But it seems its not working, old graphics remain in the background. We are using this code to remove the previous screen:

private Screen RemoveScreen() {
        Screen screen = (Screen)gameScreens.Peek();
        OnScreenChange -= screen.ScreenChange;
        Game.Components.Remove(screen);
        screen.contentManager.Unload ();
        return gameScreens.Pop();
    }

We have done some research, and came across a possible solution to give every screen its own ContentManager. When we switch screens and nullify our old screen we run ContentManager.Unload() before we nullify it. Unfortunately its not working (old graphics remain being drawn, very weird flickering graphics). To clarify the problem i made this small youtube video, you can see the home screen, when i go the setting screen you can see the old homescreen while it should be removed: http://youtu.be/ii0qD6PusA8

I hope anyone can help us.

1
Are you redrawing your screen anywhere?JWiley
No, just in the draw method of the class. But we nullify the class so it should not be drawn.Leon Boon
check if functions for update and draw are not executed in previous screen. I use enumerator for screen state, and i update and draw only chose screen.Davor Mlinaric

1 Answers

0
votes

Are you clearing your Graphics Device resource buffers before you call your draw code?

GraphicsDevice.Clear(Color.CornflowerBlue);

If you are doing this and the problem persists, then you probably still have your old screen as a component still.

Try setting up a break point before and after the Screen Remove code is called and using the debugger to verify if your components list still contains the screen that was supposed to be removed.