Loading Bar?
Blitz3D Forums/Blitz3D Beginners Area/Loading Bar?
| ||
How do you make those loading bar things that show how much is loaded? How do I make it so the bar increases a bit everytime something has finished loading(an image or a music file)? -thanks |
| ||
graphics 640,480 size = filesize("filename.dat") ;total length of the file. infile = readfile("filename.dat") while not eof(infile) readdata() ;read some data from the file. p = filepos(infile) rect 0,0,(640*p)/size,40,1 wend Just off the top of my head, but something like that should work |
| ||
For the theory part: 1. You have to know how many files you have to load 2. load file by file 3. After each file has been loaded you calculate the percentage of files loaded in comparison to maximum 4. You draw some kind of output Another examplecode (only checking for complete files loaded): Graphics 640, 480, 16, 2 SetBuffer BackBuffer() total = 100 Dim files(total) For i = 1 To total files(i) = CreateImage(320,320) ; Create or Load files/media Cls Text 320, 240, "Loading...", True, True Rect 240, 280, Float(i) / Float(total) * 160, 20, True Flip Next |
| ||
Store each frame of the loading bar in a separate image (or use anim image). Here is how I did it, though it isn't as good as Grisu's code.DrawImage loading1, 100,100 img1 = LoadImage("img1.bmp") img2 = LoadImage("img2.bmp") Cls DrawImage loading2, 100, 100 img3 = LoadImage("img3.bmp") img4 = LoadImage("img4.bmp") Cls DrawImage loading3, 100,100 Though Grisu's code is so much more practicle. |
| ||
Or try something like this:function load_progress(percent#) setbuffer frontbuffer() xrel#=graphicswidth()/640.0 yrel#=graphicsheight()/480.0 rect 0,(graphicsheight()/2.0)-(10.0*yrel) ,6.4*xrel#*percent, 20.0*yrel, 1 setbuffer backbuffer() end function now you can insert some calls to this function between the loading steps, eg: load_progress(20) ;load meshes... load_progress(40) ; load sounds etc. load_progress(60) ; initialize network load_progress(80) ; initialize player load_progress(100) ; start main game loop |