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

2017/2/25

Stop world problem

joshuadswa joshuadswa

2017/2/25

#
Hello :) I have some problem with how to stop the world >.< so basically i want to stop the music when it go to another world, but the music still playing .-. i have no idea why, >.< please help here's my code (Actor class)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Testing1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Testing1 extends Actor
{
    /**
     * Act - do whatever the Testing1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */

    public void act() 
    {
        clickedCheck();
        
    }    
    public void clickedCheck()
    {   
      if (Greenfoot.mouseClicked(this))
      {
           ((World1)getWorld()).stopped();
           Greenfoot.setWorld(new World2());
      }
    }
}
Super_Hippo Super_Hippo

2017/2/25

#
Where do you create and start the music? What is the 'stopped' method in your World1 class (=did you override it)?
joshuadswa joshuadswa

2017/2/26

#
i create and start the music on the world1, o.o theres no "stopped" method in my world1 .-., can you help me?
Super_Hippo Super_Hippo

2017/2/26

#
Who suggested to use the 'stopped' method then? Keep a reference to the GreenfootSound object in your world subclass and then stop this sound before moving to the next world.
Nosson1459 Nosson1459

2017/2/26

#
joshuadswa wrote...
i create and start the music on the world1, o.o theres no "stopped" method in my world1 .-., can you help me?
If there is no stopped method in your world one then how can you do:
((World1)getWorld()).stopped();
? The reason in having it is probably so that when the user presses "Pause" the music will also pause and when the user presses "Run" the sound resumes.
joshuadswa joshuadswa

2017/2/26

#
i read some scenario before, and i think i misunderstood its concept, >.< so is theres tutorial how to stop the music when move to another world? >.<
Nosson1459 Nosson1459

2017/2/26

#
In the same place that you have the coding for switching worlds, stop the music right before that.
danpost danpost

2017/2/26

#
First, do not use Greenfoot.playSound if you intend to control the sound in any way. You need a reference to the GreenfootSound object in order to control it:
private GreenfootSound bgMusic = new GreenootSound("<< background music filename >>");
Then, you can start it from within the constructor (which may start it before 'Run' is clicked) or you can add the following method to have it start when the 'Run' button is clicked:
public void started()
{
    bgMusic.playLoop();
}
You can do similar to stop the music:
public void stopped()
{
    bgMusic.pause();
}
(@Nosson1459, there is a 'stopped' method in the World class which is inherited by all subclasses; so, you can still call 'stopped' in any World subclass regardless of whether a 'stopped' method is in that subclass -- it jut will not do anything if the method is not overridden in the subclass) The 'stopped' method is called when the 'Pause' button is pressed (or a Greenfoot.stop command is executed) while that world is active; however, you can still programmatically call the method even if the scenario is not stopping. So, your line above would then work for when changing worlds.
Nosson1459 Nosson1459

2017/2/26

#
The point was that joshuadswa wanted to stop the music when switching worlds, pausing the music when "Pause" is pressed wasn't metioned.
joshuadswa wrote...
i read some scenario before, and i think i misunderstood its concept, >.< so is theres tutorial how to stop the music when move to another world? >.<
danpost danpost

2017/2/26

#
Nosson1459 wrote...
The point was that joshuadswa wanted to stop the music when switching worlds
My summary/closer was:
your line above would then work for when changing worlds.
pausing the music when "Pause" is pressed wasn't metioned.
I mentioned it as an added benefit of making use of the 'stopped' method.
Nosson1459 Nosson1459

2017/2/26

#
danpost wrote...
Nosson1459 wrote...
The point was that joshuadswa wanted to stop the music when switching worlds
My summary/closer was:
your line above would then work for when changing worlds.
I don't understand what you mean "My summary/closer was"
pausing the music when "Pause" is pressed wasn't metioned.
I mentioned it as an added benefit of making use of the 'stopped' method.
There was nothing wrong with saying it, but that's the reason for me saying what I said
danpost danpost

2017/2/26

#
Nosson1459 wrote...
I don't understand what you mean "My summary/closer was"
Evidentally.
There was nothing wrong with saying it, but that's the reason for me saying what I said
If you have no point, then there is no need to say anything.
Nosson1459 Nosson1459

2017/2/26

#
Nosson1459 wrote...
In the same place that you have the coding for switching worlds, stop the music right before that.
This is what I mean by "but that's the reason for me saying what I said". Then you said:
danpost wrote...
(@Nosson1459, there is a 'stopped' method in the World class which is inherited by all subclasses; so, you can still call 'stopped' in any World subclass regardless of whether a 'stopped' method is in that subclass -- it jut will not do anything if the method is not overridden in the subclass)
danpost wrote...
My summary/closer was:
your line above would then work for when changing worlds.
danpost wrote...
Nosson1459 wrote...
I don't understand what you mean "My summary/closer was"
Evidentally.
There was nothing wrong with saying it, but that's the reason for me saying what I said
If you have no point, then there is no need to say anything.
And I still don't see what this means "My closer was: your line above would then work for when changing worlds."? (It doesn't make sense with the word "closer".)
joshuadswa joshuadswa

2017/2/26

#
Thx a lot :D both of you are the best ^^
You need to login to post a reply.