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

2017/10/24

i can't get my background music to stop playing after i pause the game

1
2
darkenders darkenders

2017/10/25

#
like as in coding a function?
danpost danpost

2017/10/25

#
darkenders wrote...
like as in coding a function?
That would be affirmative.
darkenders darkenders

2017/10/26

#
ok sorry, like i said i'm new to java so again, could you show me the code for that
danpost danpost

2017/10/26

#
darkenders wrote...
ok sorry, like i said i'm new to java so again, could you show me the code for that
1
2
3
4
public void stopped()
{
    // code to pause (or stop) the music here
}
darkenders darkenders

2017/10/26

#
i could you also show me the code for the function?
danpost danpost

2017/10/26

#
darkenders wrote...
i could you also show me the code for the function?
Tell me again what you want to happen when the scenario is paused (or stopped).
darkenders darkenders

2017/10/26

#
i would like the music to stop and when i start the scenario i want it to start
danpost danpost

2017/10/26

#
darkenders wrote...
i would like the music to stop and when i start the scenario i want it to start
Then, use the 'stopped' method to stop the music and use the 'started' method to start the music. It should be obvious what code goes in what method.
darkenders darkenders

2017/10/26

#
its just that i just started like a couple of days ago so i don't know very much about java so could you please show me how?
danpost danpost

2017/10/26

#
darkenders wrote...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import greenfoot.*;
  
// class declaration statement
public class myWorld extends World
// ***  end class header  ***
 
// *** begin class code  ***
{
    // field declaration statement(s)
    GreenfootSound backgroundMusic = new GreenfootSound("circles.mp3");
 
    // ***  begin instance object constructor(s)  ***
    public myWorld()
    {
        super(600, 400, 1);
        backgroundMusic.playLoop();
        // etc.
 
        prepare();
    }
You gave this code previously. Line 16 goes in the 'started' method (remove it from where it was in the constructor). You can guess or figure out what goes in the 'stopped' method. See the GreenfootSound API documentation if still not sure.
darkenders darkenders

2017/10/28

#
1
2
3
4
public void stop()
{
       backgroundMusic.stopLoop();
}
danpost danpost

2017/10/28

#
There is no 'stopLoop' method listed in the GreenfootSound API documentation I gave a link to above. Try again. Make use of the documentation. You do not have to memorize it. Just give it a once over to see what is available in the class.
You need to login to post a reply.
1
2