How do I show loading bar during function

0 favourites
  • 6 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • I have a huge, extensive function that generates a 100,000 tile map, but I cannot for the life of my figure out how to display the loading progress to the user. I have tried making a loading bar and updating it from inside of the loops but it seems to skip past everything and still just freezes for 12 seconds. My suspicion is that everything is happening inside of one game tick, but if that is true what is a good way to give the game time to update the visual for the user in between?

  • Yes, you are probably doing everything in one tick.

    Have you tried inserting Wait 0.1 here and there in your function to allow the screen to refresh?

    Just be aware that function "forgets" its parameters and all local variables after the Wait. You need to store them in global variables or somewhere else.

  • The wait command doesn't seem to work It seems more like it is issuing 100,000 wait 0.1 second commands all at the same time. I might rework this to only continue to generate level under a certain amount of FPS. cpuutil or some command like that if that.

    UPDATE: It seems to work very easily in segments outside of the loops. I can cycle through generating terrain, ore, trees and update the player before each task by using a 0.1 wait just like you said! Thank you!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, of course you shouldn't place Wait into your main loop which you repeat 100.000 times.

    You should make sure it's called no more than 10-100 times.

    Here is an example:

    Another thing you can try is to modify your function so that it will only generate part of your 100,000 tile map, for example 10,000 tiles.

    When the function ends, it updates the progress bar and starts a timer for 0.1s.

    After 0.1s the timer calls this function again and the next 10,000 tiles are generated.

    Repeat this until the entire tile map is filled.

  • I have it working now thanks to you guys.

    Eventually as a side project I want to learn to process the tasks using a fps kept in calculation by rotating logo. Maybe even one using cpuutil expressions. Ultimately I think keeping track of progress in the current task/loop and only operating enough per tick to be limited by cpuutil or fps and reporting the progress at the end of the tick would be the best way to report loading and one day I shall make it happen.

  • So how did you get the loading bar working?

    Could you post a screenshot?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)