I finished my game programming but I have small problem, please help me I want to finish it completely. I am starting background music when the user goes to the PlayScreen and when the kid in the game dies, the background music stops and starts game over music and move to game over screen, then the user goes to the menu screen and choose the level he wants then go back to the PlayScreen but the back music isn't working again, I didn't know how to solve it although the music is working very well when start the game and when the user win the level, but it is not working when the kid dies. here is the code where I stop the music in the kid class:
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;
}
And here is the code where I start the music in the constructor of the 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();
}