'' ... in your main class...
Field soundLoader:SoundLoader
Field soundLoadStart:bool = false
'' ...in your main loader....
Method OnCreate()
soundLoader = New SoundLoader(path, soundLoader)
End
Method OnUpdate()
If not soundLoadStart Then soundLoader.Start(); soundLoadStart=true '' call this once
UpdateAsyncEvents()
'' ... etc...
'' ...later on...
Local mysound:Sound = soundLoader.GetSound( path )
End
''...elsewhere...
Class SoundLoader Extends AsyncSoundLoader Implements IOnLoadSoundComplete
Field sounds:StringMap = New StringMap
Method OnLoadSoundComplete (sound:Sound,path:String,callback:SoundLoader)
'' flag sound as loaded
sounds.Set(path,sound)
End
Method GetSound:Sound(path:String)
''if this returns null, it wasn't loaded
Return sounds.Get(path)
End
End
so i didn't test this, just did it off my head. this example doesn't check for files not found, but could be added by throwing a flag or throwing an exception, then using a try/catch around the UpdateAsyncEvents.
|