; WorldAssetSound Example ; ----------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-5 light=CreateLight() RotateEntity light,45,45,0 ; A spinning crate stands in for a shooting player crate=CreateCube() PositionEntity crate,0,1,0 EntityColor crate,80,170,255 ; Load the asset manifest world in the background manifest=LoadWorldAsync("../../../samples/worlds/asset-preload.world") While Not WorldReady(manifest) If WorldLoadState(manifest)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(manifest) Cls Text 0,0,"Loading the asset manifest..." Flip Wend ; WorldAssetSound turns the ready sound asset into an ordinary ; sound reference, decoded on a worker thread during loading sound_asset=FindWorldAsset(manifest,"ready-sound") sound=WorldAssetSound(sound_asset) ; The reference survives freeing the source manifest world FreeWorld manifest channel=0 While Not KeyDown(1) ; Space fires the asset sound If KeyHit(57) Then channel=PlaySound(sound) If channel And ChannelPlaying(channel) Then playing=1 Else playing=0 TurnEntity crate,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: play the asset sound Arrow keys: move camera Esc: exit" Text 0,20,"WorldAssetSound returned sound "+sound+" playing = "+playing Flip Wend FreeSound sound End