当用户进入PlayScreen时我开始播放背景音乐,当游戏中的孩子死亡时,背景音乐停止并开始游戏而不是音乐并通过屏幕移动到游戏,然后用户进入菜单屏幕并选择他想要的级别然后回到PlayScreen,但后面的音乐不再工作,我不知道怎么解决它虽然音乐在开始游戏时工作得非常好,当用户赢得关卡时,但它当孩子去世时,它不起作用。这是我停止孩子班级音乐的代码:
public State getState()
{
//Gdx.app.log(Float.toString(b2body.getLinearVelocity().x),"hi");
if ((Hud.getTime()<0)) {
Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
Fruits.manager.get("music/fail.mp3", Sound.class).play();
collectoIsDead=true;
Filter filter = new Filter();
filter.maskBits = Fruits.NOTHING_BIT;
for (Fixture fixture : b2body.getFixtureList())
fixture.setFilterData(filter);
b2body.applyLinearImpulse(new Vector2(0, 5f), b2body.getWorldCenter(), true);
//b2body.applyLinearImpulse(new Vector2(0,-2.5f), b2body.getWorldCenter(), true);
Hud.setTime();// to prevent the action of applying more times
return State.DEAD;
}
if ( Rockhit()) {
Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
Fruits.manager.get("music/fail.mp3", Sound.class).play();
collectoIsDead=true;
Filter filter = new Filter();
filter.maskBits = Fruits.NOTHING_BIT;
for (Fixture fixture : b2body.getFixtureList())
fixture.setFilterData(filter);
b2body.applyLinearImpulse(new Vector2(0, 5f), b2body.getWorldCenter(), true);
//b2body.applyLinearImpulse(new Vector2(0,-2.5f), b2body.getWorldCenter(), true);
return State.DEAD;
}
if((Hud.getTime()==0&& Hud.getScore()>=(level*30)+50)|| (Hud.getScore()>=(level*30)+50)) {
Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
Fruits.manager.get("music/cheering.mp3", Sound.class).play();
return State.SUCCESS;
}
if (b2body.getLinearVelocity().x!=0)
return State.RUNNING;
else
return State.STANDING;
}
这是我在PlayScreen的构造函数中启动音乐的代码:
public PlayScreen(Fruits game, float level)
{
this.level=level;
this.game=game;
gamecam=new OrthographicCamera();
gameport=new FitViewport(Fruits.V_WIDTH/Fruits.PPM,Fruits.V_HIEGT/Fruits.PPM,gamecam);
hud=new Hud(game.batch,level);
atlas=new TextureAtlas("mypack.pack");
mapLoader=new TmxMapLoader();
map=mapLoader.load("world10.tmx");
renderer=new OrthogonalTiledMapRenderer(map,1/Fruits.PPM);
gamecam.position.set(gameport.getWorldWidth()/2,gameport.getWorldHeight()/2f,0);
globalcounter=100;
world=new World(new Vector2(0,-10),true);
b2dr=new Box2DDebugRenderer();
new B2WorldCreator(this);
player=new Collector(world,this,level);
world.setContactListener(new WorldContactListener());
controller=new Controller(game.batch);
music=Fruits.manager.get("music/Backmusic.ogg", Music.class);
music.setLooping(true);
music.play();
}