0

The loading time for my game in XNA is insane (up to 1 minute), and the screen while loading before the first draw is all white, triggering people to believe it's a bug and close the application. I need help creating some kind of message for them (such as a Splash Screen) so they know that the white screen is a loading screen, or better yet, exchange the whitescreen for a picture.

The game project is made in XNA, using VB.NET. The answers i found thus far either applies to something else, or they haven't worked. I have tried to add a draw of a picture in the load content section (as suggested by a person), such as this:

spritebach.begin
draw my picture
spritebatch.end
GraphicsDevice.Present()

This does nothing, however. The picture doesn't even show, and the same white screen shows until the first draw.

To be clear, I don't want a picture showing after the game started (as suggested by some answers to other posts) with a "press a button to start". I already have an intro video starting as soon as loaded. I want something instead of the white screen during loading the game.

Additional tests:

I tried drawing in the loadcontent and in the update function (letting loading of all the assets wait), but it doesnt draw in any other function than the draw function. Also, when I put an "Exit Sub" early in the draw function, the loading time is reduced to a few seconds. So its not the loading of the content per se that takes time, but the first time the drawfunction is loaded, IF an exit sub isnt placed early.

Any help on this would be greatly appreciated!

1 Answers1

1

Ok. My answer perhaps is NOT exactly what you want because it is for Monogame (XNA) specifically. But I think the idea is the same. Below is how I implemented splash screen in my game.

In declaration phase:

bool isLoadded;//= false by default

In LoadContent():

//Load background image and spriteFont if necessary
fontBold = Content.Load<SpriteFont>("Arial_Normal_Windows"),//spriteFont
texLoadingBackground = Content.Load<Texture2D>(@"Arts\loadingBackground");
imageLoadingBackground = new ImageBackground(texLoadingBackground, Color.White, GraphicsDevice);//load the background you need to draw
//Then load everything you need after that
LoadGameContent();//
//After loading everything
isLoaded = true;

In Draw() method:

    if (!isLoaded)
    {
        GraphicsDevice.Clear(new Color(222, 184, 135));

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

        imageLoadingBackground.Draw(spriteBatch);//only draw the background image while loading
        spriteBatch.DrawString(fontBold, "LOADING...",
            new Vector2(screenWidth / 2 - fontBold.MeasureString("LOADING...").X / 2 * scaleLarge,
            screenHeight / 2),
            Color.Black,
            0, new Vector2(0, 0), scaleLarge, SpriteEffects.None, 0);//and some text

        spriteBatch.End();
    }

    if (isLoaded)
    {        
        spriteBatch.Begin();
        //draw your main screen here
        spriteBatch.End();
    }

Moreover, in my main LoadContent() method, I use:

ThreadPool.QueueUserWorkItem(state =>
            {
                LoadGameContent();
            });

to call the method to load my game content.

Just change the syntax to match your VBA program, and Draw() method as well.

Edit: For Timer to count loading time:

Declare a variable: long loadTimeForSplashContent, loadTimeForAllContent, startTime;

In the first line of LoadContent() method: loadTimeForSplashContent = DateTime.Now.Ticks;

After loading splash screen's content: loadTimeForSplashContent = (DateTime.Now.Ticks - start) / 10000;//to convert to seconds

After loading all content: loadTimeForAllContent = (DateTime.Now.Ticks - start) / 10000;//to convert to seconds

Then print them out to screen or Console to see how much they are. You need to find a similar method of DateTime.Now.Ticks in VBA to see the time at that moment (sorry I don't know).

Hope this helps!

Silver
  • 482
  • 2
  • 6
  • Yeah I tried this method, but the problem lies in loading the FIRST ever draw. So no matter what I do, it won't draw "before" that first draw, so it has to wait the same amount of time. Someone that looked at my code thought that maybe the number of spritebatch.begins/ends was the problem. Since if I put exit sub early in the draw, I can load the game in a few seconds. I am now working on changing the many thousands of draws, to only use a couple of begins/ends instead. Do you think it can be the problem? – Christian Boman Apr 15 '19 at 15:20
  • Because in the question you ask how to create a Splash/Loading Screen so my method is to do so. If you want to draw many sprites, text (or something), you just need to use spriteBatch.Begin() and spriteBatch.End() once at the beginning of your draw and at the end of your draw respectively. It doesn't matter how many content's objects that you load, Draw() method will always run even if your LoadContent() method is not fully loaded. And in your Draw() method of a smaller class (not Game1 class), you don't need to call spriteBatch.Begin() and End(). Load what are needed then draw in Splash first – Silver Apr 15 '19 at 16:07
  • You would think it does, but in my program it takes around 40 seconds before the first draw is loaded, and before then all content has been loaded long before. That's why I asked if someone knew how to create a splashscreen, so that while the first drawfunction loads, it shows some picture. It seems that's not possible though? So then it has something to do with my draw function – Christian Boman Apr 15 '19 at 16:10
  • Just to be clear, I don't feel any performance issue after the start. Though it might be there it doesn't show – Christian Boman Apr 15 '19 at 16:10
  • It is not very expensive if you use several to tens of spriteBatch.Begin() and End(). About performance and loading time, I would recommend you to use a stopwatch or timer to count how much time it needs to load content for the first draw and for all content. I will edit my answer to add this part for you. – Silver Apr 15 '19 at 16:23
  • Loading content takes a few seconds. The difference, as i said, comes when I put exit sub early in the drawfunction, or not. If I do, it somehow predicts I wont be needing the code below (maybe the thousands of spritebatch.begins/ends matter here, even if they are within If/end statements), and then it only takes a few seconds to load the first draw. If I don't put Exit Sub early, and leaves the code like it should be, it takes up to a minute – Christian Boman Apr 15 '19 at 17:30
  • I don't have your whole code so I don't understand exactly but well, you use thousands of spriteBatch.Begin/End() in your program then they affect the game's performance. – Silver Apr 16 '19 at 10:46