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

2015/8/6

More than 1 background music.

Lost_Gaming Lost_Gaming

2015/8/6

#
So i'm making my own game right? So I Wanted the Main Menu and The Option Menu to have the same music and it does, fine. but i also wanted to have a different song for the actual game. But, it keeps playing the Loop even into the game, and I just want to know how to stop the music when i go into the game... Quick replies please! this is the main menu code,
GreenfootSound MenuMusic = new GreenfootSound("MainMenu.wav");

    /**
     * Constructor for objects of class Map.
     * 
     */
    public Map()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 850, 1);
        

    }
    public void started()
    {
        MenuMusic.playLoop();
    }
    public void  stopped()
    {
        MenuMusic.stop();
    }
Please help!
danpost danpost

2015/8/6

#
Your 'stopped' method will only stop the music if you explicitly call the method or when the scenario goes out of a running state while a Map world is active. What you may not have understood is that exiting a Map world by setting a new world active does not call the method. Just call the method explicitly at the time you set the new world active.
Lost_Gaming Lost_Gaming

2015/8/6

#
can you show me in code please? thanks for the reply :D
danpost danpost

2015/8/6

#
You would use either
stopped();
.from within your world class or
getWorld().stopped();
from within an Actor class by an actor object that is in the world.
Lost_Gaming Lost_Gaming

2015/8/7

#
would I put this in the act of Map?(Map is the world that i dont want the music in...)
import greenfoot.*;

/**
 * Write a description of class Map here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Map extends World
{
    GreenfootSound MenuMusic = new GreenfootSound("MainMenu.wav");
    
    /**
     * Constructor for objects of class Map.
     * 
     */
    public Map()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 850, 1);
        getWorld().stopped();
        

    }
    public void started()
    {
        MenuMusic.playLoop();
    }
    public void  stopped()
    {
        MenuMusic.stop();
    }
}
danpost danpost

2015/8/7

#
If you do not want the music in the Map class, then you should not have line 11 and line 21 (which, as written, is not valid for a world class object) in this class. You probably should not have those particular 'started' and 'stopped' methods in this class either. They should mostly be in the class where the music is started. The code to stop the music should be at the location where you create and set a new Map world active.
You need to login to post a reply.