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

2021/1/31

background music

ekosanji ekosanji

2021/1/31

#
how to add background music from one background to another?
danpost danpost

2021/1/31

#
ekosanji wrote...
how to add background music from one background to another?
Use my background music support class found in my BGMusic Actor Class Demo scenario.
ekosanji ekosanji

2021/1/31

#
I have made the coding, but I am confused by this coding. because when the initial display sounded out, then moved to another display lost the sound.
ekosanji ekosanji

2021/1/31

#
public class Menu extends World{ GreenfootSound myMusic = new GreenfootSound("Stages/Opening.mp3"); GreenfootSound myMusic1 = new GreenfootSound("Stages/Stage1.mp3"); /** * The startButton variable stores a button object. */ private Actor startButton; /** * The howToPlayButton variable stores a button object. */ private Actor howToPlayButton; /** * The historyButton variable stores a button object. */ private Actor historyButton; /** * The creditsButton variable stores a button object. */ private Actor creditsButton; /** * The Menu constructor creates a new Main Menu screen with the respective information and buttons. */ public Menu(){ super(600, 400, 1); setBackground("images/World/Menu/Portada.png"); startButton = addButton("New Game",430,120,Color.WHITE); howToPlayButton = addButton("How to play",430,200,Color.WHITE); historyButton = addButton("History",430,280,Color.WHITE); creditsButton = addButton("Credits",430,360,Color.WHITE); } /** * The act method verifies if a button has been pressed. * If the "New Game" button has been pressed, we initialize a new game. * If the "How to play" button has been pressed, we display how to play information. * If the "History" button has been pressed, we display the game history. * If the "Credits" button has been pressed, we display the credits. */ public void act(){ myMusic.play(); if(Greenfoot.mouseClicked(startButton)){ myMusic.pause(); myMusic1.play(); Difficulty world = new Difficulty(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(howToPlayButton)){ myMusic.pause(); HowToPlay world = new HowToPlay(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(historyButton)){ myMusic.stop(); History world = new History(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(creditsButton)){ myMusic.stop(); Credits world = new Credits(); Greenfoot.setWorld(world); } } /** * The addButton creates a new custom button on a XY coordinates. * @return A custom button. */ private Actor addButton(String s, int x, int y, Color color){ Actor button = new Label(s,50,color); addObject(button, x, y); return button; } }
ekosanji ekosanji

2021/1/31

#
this is my coding, but I'm confused why the sound doesn't come out.
danpost danpost

2021/1/31

#
ekosanji wrote...
this is my coding, but I'm confused why the sound doesn't come out.
Try changing first line in act method to:
if ( ! myMusic.isPlaying() ) myMusic.play();
ekosanji ekosanji

2021/1/31

#
This way??? public void act(){ if ( ! myMusic.isPlaying() ) myMusic.play(); if(Greenfoot.mouseClicked(startButton)){ myMusic.pause(); myMusic1.play(); Difficulty world = new Difficulty(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(howToPlayButton)){ myMusic.pause(); myMusic1.play(); HowToPlay world = new HowToPlay(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(historyButton)){ myMusic.stop(); myMusic1.play(); History world = new History(); Greenfoot.setWorld(world); } else if(Greenfoot.mouseClicked(creditsButton)){ myMusic.stop(); myMusic1.play(); Credits world = new Credits(); Greenfoot.setWorld(world); } }
danpost danpost

2021/1/31

#
ekosanji wrote...
This way??? << Code Omitted >>
Did that change anything?
You need to login to post a reply.