我通常在原始项目中执行任务之前用于在“虚拟”上测试它,同样现在测试“背景音乐的音量设置”即增加和减少cocos2d-android项目中音乐的音量,但是这个适用于“虚拟”项目不在原始项目上,我比较了代码,但无法得到它不工作的原因:( 这是代码。
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);
}