Resolution change

Everything else that doesn't fall into one of the other categories.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Resolution change

Post by MrTAToad »

I've got my screen resolution change routine up and running, okay. What was surprising is that it seems that sounds and system fonts are cached (and don't call the loading binding), whilst sprites aren't cached. This called my loading system a few problems, until I decided to check to make sure that the relevant item is present after using LoadSound/LoadFont. Unfortunately, it doesn't quite work as expected as even with different sessions, the sound is still cached...

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")
If you click on the Unload button, the sounds are freed and reloaded, but neither the Loading or LoadingError procedures are called...
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: Resolution change

Post by MrTAToad »

I presume graphics still have to be reloaded if the screen and window is closed ?

What about if just the screen is closed ?
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: Resolution change

Post by MrTAToad »

Found a way of making sure everything isn't cache, by appending "?" plus a random time to all loaded files... See http://stackoverflow.com/questions/2582 ... nging-file
Post Reply