This doesn't work with LoadSprite as the sprite is deemed valid after the LoadSprite, even if nothing is loaded...
Does everything still have to be unloaded and then reloaded after a resolution change , or is this no longer needed ?
This modified code will show you what I mean about cached sounds :
Code: Select all
;
; ------------------------------------------------------------
;
; SpiderBasic - Sound example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
; Note: should use Chrome to use WebAudio API
;
Declare Start()
InitSound()
Global NbLoadedElements
Procedure PlayLazerEvent()
Debug "Start"
; If SoundStatus(0)=#PB_Sound_Stopped
; Debug "Not playing"
; EndIf
Debug "End"
PlaySound(0)
EndProcedure
Procedure PlaySirenEvent()
PlaySound(1)
EndProcedure
Procedure UnloadAndReload()
Debug "Free"
NbLoadedElements=0
CloseWindow(0)
FreeSound(0)
FreeSound(1)
LoadSound(0, "Data/Lazer.wav")
LoadSound(1, "Data/Siren.ogg")
Debug "Loaded"
Start()
EndProcedure
Procedure Start()
If OpenWindow(0, 0, 0, 200, 190, "Sound example", #PB_Window_TitleBar | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 180, 30, "Play Lazer !")
ButtonGadget(1, 10, 50, 180, 30, "Play Siren !")
ButtonGadget(2,10,90,180,30,"Unload and reload")
BindGadgetEvent(0, @PlayLazerEvent())
BindGadgetEvent(1, @PlaySirenEvent())
BindGadgetEvent(2,@UnloadAndReload())
EndIf
EndProcedure
Procedure Loading(Type, Filename$, ObjectId)
Debug Filename$ + " loaded (id = " + ObjectId + ")"
NbLoadedElements+1
If NbLoadedElements = 2 ; Finished the loading of all sounds, we can start the application
Start()
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadSound(0, "Data/Lazer.wav")
LoadSound(1, "Data/Siren.ogg")