Loading bar example

  • F

    So I did some experimenting in order to have a loading bar that would update while a program loads it’s assets.

    I tried various methods to have it update smoothly, but it seems that all threads are paused while assets are loading, so I had to settle for a bar that updates in chunks, as each asset is loaded.

    I chose to implement this in a function called by a timer. This way there is no need to call any extra code in between the asset load statements.

    The example is a small sound player which loads lots of music at the start. I have added comments so that it can be easily understood.

    The position, size, and colour of the loading bar can be changed by editing the variables on line 18-23.

    The global variable loadTime should be set to the total loading time of all assets. This can for instance be measured once using the time() function, as shown in the example.

    Feel free to use in your own projects!