I usually use music.pause()
and music.resume()
(because after stop the play does not work any more, I do not know why). When you leave a scene, you can call music.pause()
. When you enter a scene, you can call music.resume();
How to add background music to gamescene in andengine
-
13-10-2022 - |
Question
bg music plays on splash,menu and gamescene when i had put the below code, but i want to make bg music to play only on my gamescene, can you please help me. Thank you.
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException
{
MusicFactory.setAssetBasePath("mfx/");
try {
music = MusicFactory.createMusicFromAsset(mEngine
.getMusicManager(), this, "abcd.wav");
music.setLooping(true);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResourcesManager.prepareManager(mEngine, this, camera, getVertexBufferObjectManager());
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
music.play();
SceneManager.getInstance().createSplashScene(pOnCreateSceneCallback);
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow