play sound||doc135479

September 20, 2022


 Entity:play3dSound(filename, isLoop) 
  • The class to which the function belongs:Entity


Play sound effects.


  • The sound effect added by this function is a 3d type sound effect. If you add a non-main client entity object, the sound effect may not be heard by the player due to the distance, but adding it to the main client entity object will not have this problem. .


Variable name type Description
filename string audio file name
isLoop boolean Whether to loop playback, if true, loop playback

Value Returned

type Description
int Audio ID

Code Samples

on the client sideglobal script, register when the map load is completeCallback, add background music that loops all the time

Lib.subscribeEvent(Event.EVENT_LOAD_WORLD_END, function()
  Me:play3dSound("Media/Sound/bgm/loading.mp3", true)