How to Load Resources when...

BlitzPlus Forums/BlitzPlus Beginners Area/How to Load Resources when...

Apollonius(Posted 2005) [#1]
I'm wondering how to load in resources while the game is already running. I would really like to see how its done, I mean would anyone be willing to make a small example?

For example, when you start the game,

1. Theres a Black Screen with the text "Loading ..." and under it a loading bar using rec. forms.

How do you calculate the bytes so that the custom loading bar knows at how many % it is, so it display it through the loading bar.

And how do you make it loads images for example, instead of at the start... If this isnt clear please tell me.. I'll try to find a better way to explain this.

In any case thanks for any help given.


CS_TBL(Posted 2005) [#2]
You can only have a smooth progressbar when you do you own loading routines. When loading an image with LoadImage(file$) then this progressbar would go from 0% to 100% at once. Naturally, you don't much feel like doing your own JPG loader.. so regarding images, forget about a smooth progressbar. :P
What you *could* do is update a bar when you need to load, say, 20 images.. then after each LoadImage instruction you update this bar with another 5%.
You could ofcourse add this smooth-progress-updating in your own loading routines, such as for maps and playerdata. If you have a map of 100x100 tiles, then you could update some bar at each line of 100 .. naturally, maploading goes a little bit slower then.. question is generally if you really want all this progress-displaying at all.
A major disadvantage of your own maploader accessing a progressbar is that this loading stuff will be less modular/reusable if you directly access this progressbar. As in: each time you load a map for whatever reason you need to have a progressbar to update. Things can be solved by making things more modular, by making this progressbar not a hardcoded thing, but an independent object. Then it's all a matter of connecting this object to the maploader as function-arguement orso, then the maploader only updates the progressbar-object when you gave one (progressbar<>0). But this all is such an amount of overhead that you really should ask whether you want to display a smooth progressbar or not.


Apollonius(Posted 2005) [#3]
Smooth Progressbar isn't that important. Just loading multiple file progress bar. Lets say 20 Images and 5 txt files. I want to be able to load stuff at any given time in the game's process using a simple progressbar. However I'm not quite sure how should the code look like.

CS_TBL,
Think you could show me a small example on how you would do it?


CS_TBL(Posted 2005) [#4]
see the B+ help for:

CreateProgBar

Note that this is a windows/GUI object.. so for games it might be less suitable if you want fancy gfx.

If you need a graphical one, I'm a bit busy this week, first try it yourself. But think along the lines of:

Function CreateDeluxeProgressbar(x,y,width,height,borderimage, barimage, maxvalue)


Function DeluxeProgressbarSetvalue(bank,value)

Function DeluxeProgressbarGetvalue(bank,value)

Function UpdateDeluxeProgressbar(bank)

Function FreeDeluxeProgressbar(bank)


eventually you can use it like this:


MyProgBar=CreateDeluxeProgressbar(0,0,128,32,img1,img2,100)

; mainloop
; exit mainprogram-loop
FreeDeluxeProgressbar MyProgbar
End


See the bank-tutorials in "B+ tutorials" on how to work with banks.

I'm not sure on how it would work in practice, it's all very GUI-aimed .. anyway..

anyway, gotta go ^_^


Apollonius(Posted 2005) [#5]
The thing I don't know is how to load images without loadign them at the program's startup, because if its not at startup it creates errors, doesn't it?

I'm going more game oriented, small RPG like.


CS_TBL(Posted 2005) [#6]
You can load images anywhere, before your mainloop, in your mainloop (don't forget to free them :D), after your mainloop, in functions, anywhere.
If you can't load images at these locations I just named, you've some weird bug somewhere.. ^_^

Remember, you work with handles.. an image is just a 4-byte adres, like those '22037293'-like numbers you might see now and then. An image is for the user not much different than a gadget, a bank, a sound etc. It's all 4-byte adresses.. Each time you load an image or create something like a gadget, a new handle is made.


Apollonius(Posted 2005) [#7]
I've been playing around to get it to look like I want it to, but I'm not quite sure how to go about loading stuff.

AppTitle "Loading Module"

Const width=640,height=480
Graphics width,height,2
SetBuffer BackBuffer()

Global load_min_value 		= 1
Global load_max_value 		= 295
Global load_current_value 	= 0

Repeat
; White Stuff
Color 255,255,255
Text 290,240,"Loading..."
Rect 175,260,300,20,0
; Rewd bar
Color 150,0,0
Rect 177,263,(load_min_value+load_current_value),14,1
bob = CreateTimer(20)
If bob Then
	If(load_current_value < load_max_value ) Then
		load_current_value = load_current_value + 1
	EndIf
EndIf

Flip
Until KeyHit(1)


teach me how to work timers and custom timer.. how to make em.. cause when I tryed above.. it goes fast i cant controle it


CS_TBL(Posted 2005) [#8]
easy enough:

Graphics 640,480,32,2

SetBuffer BackBuffer()

;
; use [cursor L] & [cursor R]
;

ShowProgressbar(40,40,100,20)

Repeat
	If KeyDown(205)
		p=p+1
		ShowProgressbar(40,40,100,20,p)
	EndIf

	If KeyDown(203)
		p=p-1
		ShowProgressbar(40,40,100,20,p)
	EndIf

	Flip
Until KeyHit(1)
End

Function ShowProgressbar(x,y,w,h,percentage=0)

	If percentage>100 percentage=100
	If percentage<0 percentage=0

	; backdrop
	Color 80,0,0
	Rect x,y,w,h,1

	; bar
	Color 255,0,0
	barwidth=w*percentage/100
	Rect x,y,barwidth,h,1
	
End Function


This doesn't require any timer at all.. just update the Progressbar manually when you load (a part of) your file.
So, if you need to load 4 images, then each image is worth 25% .. then it's:

img1=LoadImage [...]
ShowProgressbar(40,40,100,20,25)

img2=LoadImage [...]
ShowProgressbar(40,40,100,20,50)

img3=LoadImage [...]
ShowProgressbar(40,40,100,20,75)

img4=LoadImage [...]
ShowProgressbar(40,40,100,20,100)

can't be easier..



about timers:

Just read the help for CreateTimer, it's clearly written all there..