2012-09-05 40 views
0

我正在使用andEngine開發遊戲。我想爲此遊戲添加背景音樂。我試着實現聲音,但聲音沒有被播放。請幫助我。這是我的代碼:andEngine中的聲音問題

onLoadEngine()

return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, 
       new FillResolutionPolicy(), this.mCamera).setNeedsSound(true)) 

onLoadResources()

Sound bgSound; 
SoundFactory.setAssetBasePath("gfx/"); 
this.bgSound = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this,    "bg.mid"); 
bgSound.setLoopCount(-1); 
bgSound.play(); 
+0

您的聲音文件是否位於assets/gfx文件夾中? – IncrediApp

+0

yes..it在資產/ gfx文件夾中。 – Andy

+0

移動setloopcount和播放調用onCreateScene – IncrediApp

回答

1

移動這些2行到onCreateScene()方法:

bgSound.setLoopCount(-1); 
bgSound.play(); 

此外,呼叫SoundFactory.createMusicFromAsset代替SoundFactory.createSoundFromAsset