This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jillyjung
Jillyjung wrote ...

2018/2/25

How I can stop the sound in another subclass of world

Jillyjung Jillyjung

2018/2/25

#
I have 3 subclass,1)Home 2)How to play 3)Game, I can play the sound from first subclass to last subclass but when game over in the 3rd class I click button return to 1st subclass the sound didn't stop and it play the new sound over the first one. I want the sound stop after I click the return button to 1subclass (button return appear after game over or win)
danpost danpost

2018/2/25

#
Cannot help without seeing what codes you are using for your sounds. Particular all codes for both sounds that play over top one another. Indicate which class all codes given are in. By "all", I mean all field declarations and all methods that have any sound control (or attempted sound control) in them.
xbLank xbLank

2018/2/25

#
Say you have music x in subclass 1 and musiy y in subclass2. When clicking a button in subclass1 you can just tell the button to stop the music in subclass1 before taking you to subclass2. You dont need to stop the music from subclass1 in subclass2.
Jillyjung Jillyjung

2018/2/25

#
//1st subclass code public class Start extends World { GreenfootSound myMusic = new GreenfootSound("(Free No Copyright Music) A New Day - Gaming Music Copyright Free.mp3"); public Start() { super(1024, 600, 1, false); addObject(new startbtn(),520,400); } public void act(){ myMusic.play(); } } //3rd subclass actor public void act() { checkfall(); checkKeys(); Ceiling(); fall(); stopAtEdge(); Actor bonus = getOneIntersectingObject(bonus.class); Actor fish = getOneIntersectingObject(fish.class); if(bonus != null){ getWorld().removeObject(bonus); count++; if(count == 3){ counter = true; } }else{ if(counter == true && fish !=null ){ getWorld().removeObject(fish); finish(); } } if(getY()>getWorld().getHeight()+100){ outOfWorld(); } } public void finish(){ World myWorld = getWorld(); Win win = new Win(); myWorld.addObject(win,myWorld.getWidth()/2,(myWorld.getHeight()/2)-100); myWorld.addObject(new returnbtn(),500,400); } public void outOfWorld(){ World myWorld = getWorld(); GameOver gameover = new GameOver(); myWorld.addObject(gameover,myWorld.getWidth()/2,(myWorld.getHeight()/2)-100); myWorld.removeObject(this); myWorld.addObject(new returnbtn(),500,400); } // Actor Gameover public class GameOver extends Actor { public GameOver(){ setImage(new GreenfootImage("Game Over",150,Color.WHITE, Color.BLACK)); } } //Actor Win public class Win extends Actor { public Win(){ setImage(new GreenfootImage("WIN!!!",150,Color.PINK, Color.BLACK)); } } // Actor returnbtn public class returnbtn extends Actor { public void act() { if(Greenfoot.mouseClicked(this)){ Greenfoot.setWorld(new Start()); } } }
Jillyjung Jillyjung

2018/2/25

#
I want only music X play along all subclass but when the game is end and I click return to 1st start subclass it play new music X again overlap with the first one that play before. I don't want to play overlap so I want to stop it before it return to 1st subclass.
danpost danpost

2018/2/25

#
Change:
1
2
3
GreenfootSound myMusic = new GreenfootSound("(Free No Copyright Music) A New Day - Gaming Music Copyright Free.mp3");
// to
static GreenfootSound myMusic = new GreenfootSound("(Free No Copyright Music) A New Day - Gaming Music Copyright Free.mp3");
Jillyjung Jillyjung

2018/2/26

#
thank you so much
You need to login to post a reply.