Load textures while playing

For my 2D game:
While playing I need to load some large 2D textures (2000x2500 pixels) and unload some others.
Of course I want to load and unload texture2D without game / draw freeze (or less ...): x I don't know if this is possible.

I am already using a stream to load some texture while drawing the loading screen

//thread Loading
ThreadStart th_loadingScreen = delegate { DisplayLoading(LoadingScreen); };
new Thread(th_loadingScreen).Start();

      

But I think this is quite different.

Of course I tried something:

private void LoadUnload()
{
    for (int j = 0; j <= NbrRow; j++)
        for (int i = 0; i <= NbrCol; i++)
        {
            if(somethingTrue)
            {
                ThreadStart th_LoadInGame = delegate
                    {
                        LoadInGame(i, j, TextureStringPathToLoad);
                    };
                new Thread(th_LoadInGame).Start();
            }
        }
}

      

But I have a little freeze.

And I know how to unload the content, but I don't know how to unload one loaded texture: x

+3


source to share


1 answer


It is not possible to unload individual elements within an object ContentManager

. So, I do several ContentManager

and share what I need among them. That way I can Unload

, for example, keep the rest in memory.

As far as the little hover you see, the thread alone does not guarantee no hiccups or the like. I would chat with the property Thread

Priority

; try installing it below and see what happens. However, this is not a guarantee. From the article:



Operating systems are not required to respect thread priority.

+2


source







All Articles