我通常在执行原始项目中的任务之前在“虚拟”上进行测试,现在同样测试了“背景音乐的音量设置”,即在 cocos2d-android 项目中增加和减少音乐的音量,但这适用于“ dummy”项目不在原始项目中,我比较了代码,但不明白为什么它不起作用:(这是代码。
public class SplashScene extends CCLayer {
public SplashScene() {
super();
// TODO Auto-generated constructor stub
Global.createSprite(this, "splash_320x480.png", 160, 240);
schedule("gameBegin", 5);
Context context = CCDirector.sharedDirector().getActivity();
SoundEngine.sharedEngine().preloadEffect(context, R.raw.pew_pew_lei);
SoundEngine.sharedEngine().playSound(context, R.raw.rock, true);
}
MainActivity.java
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
Global.m_SoundEngine.setSoundVolume(1.0f);
Global.m_SoundEngine.setEffectsVolume(1.0f);
} else {
Global.m_SoundEngine.setSoundVolume(0.0f);
Global.m_SoundEngine.setEffectsVolume(0.0f);
}
super.onWindowFocusChanged(hasFocus);
}