How make a loader bar like in flash?¿

Previous topic - Next topic

mentalthink

HI I have a doubt about this...
I have a bunch of media to load, but I like to make something like a web Flash bar, something screen on I can draw an animated sprite while the bar increment.

I don´t have very clear how make it, I have to call Showscreen, very time I load a 3d_Object, sprite or Sound, or another way for simply this task.

Kinds Regards,
Iván J.

Ruidesco

Yes, basically the idea is having every element listed in an array, then looping the loading process and drawing the progress bar filling depending on the percentage of elements you have already loaded.

mentalthink


Crivens

It's what I do on my newest code for resizing all images for the resolution. If I have time and I remember tonight I will post it, but really all it does is get the file list from the media directory and then process one at a time (only picking up PNG and BMP). For every one it does it works out the percentage of files it has processed and updates the bar. All I really do is draw a red rectangle that covers the whole resolution width for the bar then draw a blue one with a width of the percentage processed. Is pretty simple but works well for me.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

ampos

Code (glbasic) Select
things_to_load=a_lot_of_sprites

repeat
   drawrect 0,0,things_loaded*(bar_lenght/things_to_load),height
   load_a_thing()
   inc things_loaded
   showscreen()
until you_are_done


Pseudocode  :P
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Crivens

Something like that. Except I take the resolution into account, and also draw a different coloured rectangle first that fills up the entire width. So you have the effect of a red bar across the screen that gradually fills with blue.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

mentalthink

Ok, I thinked in this, but my code have a lot of sprites declared, and reload the media folder, and after put in order, I think it´s a lot of work, I think I go to make a simple Showscreen every time.

But a doubt, imagine I want put an sprite or somthing in 3d turning around self, not it´s possible, not, because if in a 1 pass read all the data the rotation, or change of the sprite will be ridicolous...

Crivens

I'm not sure now what you were saying is exactly what we think you are asking (a simple progress bar going across the screen as sprites are processed). Even so here is my newer code for generic resolution graphic resizing which includes a progress bar.
Code (glbasic) Select
SUB remapall: //Takes all pictures and resizes them for the device being used
CREATEDIR(docdir$)
IF x<>1 AND y<>1 //If exactly the same then you are using the device made for
LOCAL needresize=1
IF DOESFILEEXIST(docdir$+"/ver.txt") //Must exist in target directory
IF DOESFILEEXIST("ver.txt") //And in media directory
LOCAL file1=GENFILE()
OPENFILE(file1,docdir$+"/ver.txt",TRUE)
LOCAL file2=GENFILE()
OPENFILE(file2,"ver.txt",TRUE)
LOCAL file1line$,file2line$
READLINE file1,file1line$
READLINE file2,file2line$
IF file1line$=file2line$ THEN needresize=0
CLOSEFILE file1
CLOSEFILE file2
ENDIF
ENDIF
IF needresize=1
LOCAL file$[],num,i
num=GETFILELIST("*.*",file$[])
IF num>0
LOCAL barthick=20
LOCAL ilist=BOUNDS(file$[],0)-1
remapimage("config.png")
LOCAL configspr%=GENSPRITE()
LOADSPRITE docdir$+"/config.png",configspr
LOCAL configsprw%,configsprh%
GETSPRITESIZE configspr,configsprw,configsprh
FOR i=0 TO ilist
IF UCASE$(file$[i])<>"CONFIG.PNG" THEN remapimage(file$[i]) //All other files apart from config one
DRAWRECT 0,y*((targety/2)-(barthick/2)),targetx*x,barthick,RGB(255,0,0)
DRAWRECT 0,y*((targety/2)-(barthick/2)),(targetx*x)/100*((1+i)/(ilist+1)*100),barthick,RGB(0,0,255)
//PRINT "CONFIGURING...",0,y*((targety/2)-(barthick/2))+20,10
DRAWSPRITE configspr,0,y*((targety/2)-(barthick/2))-configsprh
SHOWSCREEN
NEXT
LOADSPRITE "",configspr
ENDIF
COPYFILE "ver.txt",docdir$+"/ver.txt"
ENDIF
SETCURRENTDIR(docdir$)
ENDIF
ENDSUB

FUNCTION remapimage:file$ //Takes a picture and resizes it for the device being used (not for 3D)
IF DOESFILEEXIST(file$)
LOCAL rightf$=UCASE$(RIGHT$(file$,3))
IF rightf$="PNG" OR rightf$="BMP" OR rightf$="JPG" //I know it says it can but JPG just doesn't work. Wrong colours and crashes a lot. Use PNG!
IF LEFT$(file$,2)="3D"
//COPYFILE file$,docdir$+"/"+file$ //Actually cos don't resize we just load from the original directory
ELSE
LOCAL width,height
LOCAL usesprite=GENSPRITE()
LOADSPRITE file$,usesprite
GETSPRITESIZE usesprite,width,height
LOCAL pix%[]
LOCAL ok%=SPRITE2MEM(pix[],usesprite)
LOCAL pix2%[]
LOCAL zix=x
LOCAL ziy=y
LOCAL xwidth%=width*zix
IF INTEGER(xwidth)<>xwidth THEN xwidth=INTEGER(xwidth)+1
LOCAL xheight%=height*ziy
IF INTEGER(xheight)<>xheight THEN xheight=INTEGER(xheight)+1
DIM pix2%[xwidth*xheight]
LOCAL xl
LOCAL bx,by
FOR xl=0 TO BOUNDS(pix2[],0)-1
bx=INTEGER(MOD(xl,xwidth)/zix)
by=INTEGER(INTEGER(xl/xwidth)/ziy)
pix2[xl]=pix[bx+by*width]
NEXT
LOCAL usesprite2=GENSPRITE()
MEM2SPRITE(pix2[], usesprite2, xwidth, xheight)
SAVESPRITE docdir$+"/"+file$,usesprite2
LOADSPRITE "",usesprite2
LOADSPRITE "",usesprite
ENDIF
ENDIF
ENDIF
ENDFUNCTION


Now I would probably in the future use the gradient polyvector code that's around here somewhere to show a nicer bar, but I quite like the simplicity of the above code for my current game.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

MrTAToad

I'll have to upload a new version of my TSetup routine sometime - when loading stuff, I animate a progress wheel and display a 4 coloured rectangle when detecting if the internet is available...

mentalthink

Thanks Ampos, Crivens and MrTatoad for your help.

I take a deep look to my code, becuase I think I have to change a lot of lines, how I say, I think I will put a simple showscreen every line... yes a bad code  :| :'( :-[

Ruidesco

As long as things move on the screen so it shows it didn't hang up it will be alright, even if it's highly linear code.

Nathan

Copy the Microsoft Windows install solution, where the progress bar moves smoothly up to 99% in a few seconds then takes 2 minutes to do the final 1%.  Heh heh.

mentalthink

HI Nathan thanks, but for devices mobiles I think dont´s works  :P.

Thanks again.