2012-09-05 54 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