Je vous propose un petit partage sur SpiderBasic.
Ce n'est pas grand chose, il s'agit d'une barre de progression de chargement des fichiers (sprites et sons) et permet de faire patienter l'utilisateur en attendant que la page soit totalement chargée.
On pourrait même mettre une image en data pour faire plus joli...
Je n'attends pas que tous les fichiers soient chargés pour lancer le RenderFrame()...
Visible ici : http://jeuxvideobesancon.fr/2018.html
Fichiers téléchargeables http://jeuxvideobesancon.fr/Telechargement/Demo2018.zip
Code : Tout sélectionner
; SpiderBasic 2.20
; CoolDji-2018
OpenScreen(1024, 768, 32, "Hello 2018")
InitSound()
EnableExplicit
; TotalLoading = nombre de fichiers à lire : 46 sprites de lettres et 1 musique
Global j,loadingAll=0,NbLoadedElements,StartDemo,LightScreen,TotalLoading=46+1,TauxLoading.f
Global Text$,x.i,y.i,light.i,a$,i,wait$,tempowait
Declare CreateAllSprite()
Declare AffText(Text$,x.i,y.i,light.i)
For j=1 To 20:LoadFont(j, "Arial", j*2):Next
CreateAllSprite()
Procedure RenderFrame()
;----- Loop
ExamineKeyboard():ExamineMouse()
ClearScreen(RGB(255,255,255)) ; efface l'écran
If loadingAll=0 ; Les fichiers ne sont pas tous chargés
tempowait+1 ; gere la temporisation des 3 petits points du texte
If tempowait>20
tempowait=0
wait$+"."
If wait$="....":wait$="":EndIf
EndIf
StartDrawing(SpriteOutput(100)) ; modifie le sprite de la barre de temporisation
Box(0,0,SpriteWidth(100),SpriteHeight(100),RGB(255,255,255)) ; Efface tout
DrawingFont(FontID(6))
DrawText(40,0,"Loading Elements "+Str(TauxLoading*100)+"%"+wait$,RGB(72,127,140)) ; Affiche le titre de la barre
Box(0,20,SpriteWidth(100),10,RGB(72,127,140)) ; pose un rectangle bleu
Box(1,20+1,SpriteWidth(100)-2,10-2,RGB(255,255,255)) ; Evide le rectangle
Box(1,21,TauxLoading*(SpriteWidth(100)-2),10-2,RGB(36,64,70)) ; met à jour la barre en fonction du taux d'avancement de chargement des fichiers
StopDrawing()
DisplaySprite(100,1024/2-SpriteWidth(100)/2,100) ; Affiche le sprite
Else ; On est ici car tous les fichiers ont été chargés
If LightScreen=0 ; premier passage
PlaySound(0,#PB_Sound_Loop) ; joue PB => Petit Biscuit
EndIf
LightScreen+5 ; Allume l'écran noir, représenté par le sprite 101
If LightScreen>255:LightScreen=255 :EndIf
DisplayTransparentSprite(101,0,0,LightScreen)
Afftext("HELLO 2018",280,100,255) ; Affiche le texte avec la procédure Afftext
EndIf
FlipBuffers() ; continue the rendering
EndProcedure
Procedure CreateAllSprite()
CreateSprite(100,200,30) ; Sprite de la barre d'avancement
CreateSprite(101,1024,768) ; Sprite pour un ecran noir qui peut s'afficher par fade Off/On
EndProcedure
Procedure Loading(Type, Filename$)
NbLoadedElements+1
TauxLoading=NbLoadedElements/TotalLoading
Debug Filename$ + " " + NbLoadedElements +" " +TauxLoading
If NbLoadedElements = TotalLoading ; Finished the loading of all images and sounds, we can start the applications
loadingAll=1
; FlipBuffers() ; start the rendering
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
Procedure AffText(Text$,x.i,y.i,light.i) ; Affiche du text avec la police de taille normale
For j=1 To Len(Text$) ; Fait une boucle sur le nombre de caractères à afficher
a$=Mid(Text$,j,1) ; Prends un caractère après l'autre
If (Asc(a$)>=Asc("-")) And (Asc(a$)<=Asc("Z")) ; vérifie que le caractère existe
i.i=Asc(a$)-45 ; rappel : le code Ascii de $ est 36
DisplayTransparentSprite(i+1000,x+Random(4),y+Random(4),light) ; Affiche le sprite du caractere
EndIf
x+SpriteWidth(i+1000)+2
Next
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_RenderFrame, @RenderFrame())
;----- Découpe chaque caractère dans un Sprite
For j=0 To 45
LoadSprite(1000+j,"Demo2018/PoliceWar/PoliceWar"+Str(j)+".png",#PB_Sprite_AlphaBlending)
Next
LoadSound(0,"Demo2018/PB1.mp3")
FlipBuffers()