Create Background Image

I made a game for Windows 8 in monogame, but ran into a problem. Finally, we enjoyed the Surface RT, but noticed that the loading time on this device is very long. We looked at several other games and noticed that this is not uncommon. To combat the boredom of the user while loading resources, I want to draw a loading bar and some random facts on the screen. The problem is that loading resources blocks the rest of the game and does not allow me to draw anything, because it remains stuck in the initializing part.

I was looking for the creation of a lost thread, but found that the Windows Store does not support this, so now my question is to you, how can I load my resources in the background or another way not to block the full game and be able to call the my Draw () descriptor, to draw a loading bar on my screen.

+4
source share
1 answer

I did something like this:

protected volatile bool ContentLoaded = false;

protected async override void LoadContent()
{
    base.LoadContent();

    Enabled = false;
    await ThreadPool.RunAsync(new WorkItemHandler(LoadAllContent));
}

protected void LoadAllContent(Windows.Foundation.IAsyncAction action)
{
    if (action.Status == Windows.Foundation.AsyncStatus.Error)
       System.Diagnostics.Debug.WriteLine(action.ErrorCode);

    // load your contents

    ContentLoaded = true;
    Enable = true;
}

And at the beginning of your method Draw:

if (!ContentLoaded)
{
    // draw your loading screen

    return;
}

If you need a progress bar, you need a counter to increase each resource you load, and then Drawyour panel should refer to this counter in yours.

+4
source

All Articles