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

2013/3/3

NEED HELP WITH SOUND LOOP !! PLS HELP

Prish950 Prish950

2013/3/3

#
I want that every time when the run button is pressed that the music starts and every time when the run botton its paused that the music stop. PLEASE HELP!
Gevater_Tod4711 Gevater_Tod4711

2013/3/3

#
Prish950 Prish950

2013/3/3

#
no because the loop.pause dudnt work
Gevater_Tod4711 Gevater_Tod4711

2013/3/3

#
I'm not shure if it's possible to pause a loop. But you can do it if you don't use the loop. Then you just have to check whether the music is playing (using the isPlaying() method of GreenfootSound) and if not it has to be played again.
Prish950 Prish950

2013/3/3

#
but it have to be a loop :D thats the problem
danpost danpost

2013/3/3

#
You can create a manual loop with:
if(!soundFile.isPlaying()) soundFile.play();
Prish950 Prish950

2013/3/3

#
okay thanks
Prish950 Prish950

2013/3/3

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.Object;
import java.util.List;
/**
 * Write a description of class Schlachtfeld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Schlachtfeld extends World
{

    static GreenfootSound backGroundMusic = new GreenfootSound("MarioThemeAcapella.mp3"); 
    
    public static void startMusic()
    {
        if(!backGroundMusic.isPlaying()) 
        {
         backGroundMusic.play();
        }
    }
    
    public static void stopMusic()
    {
        backGroundMusic.stop();
    }


    public void act()
    {
 
            startMusic();
            
            if (Greenfoot.isKeyDown("e")) for (Object obj : getObjects(Bomb.class)) ((Bomb) obj).explode();
            if (Greenfoot.isKeyDown("m")) for (Object obj : getObjects(Bomb2.class)) ((Bomb2) obj).explode2(); 
            
            if (getObjects(Bomber1.class).isEmpty() && !getObjects(Bomber2.class).isEmpty())
            {
              winnerLuigi();
              stopMusic();
            }
            
            if (!getObjects(Bomber1.class).isEmpty() && getObjects(Bomber2.class).isEmpty())
            {
              winnerMario();
              stopMusic();
            }

     }
     
    public void winnerMario()
    {
            List objekte = getObjects(null);
            removeObjects(objekte);
            setBackground("winnerMario.jpg");
            
    }
    
    public void winnerLuigi()
    {
            List objekte = getObjects(null);
            removeObjects(objekte);
            setBackground("winnerLuigi.jpg");
            
    }

    /**
     * Constructor for objects of class Schlachtfeld.
     * 
     */
    public Schlachtfeld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(15, 9, 60); 
        
        prepare();
    }

it doesnt work i want that it stops when someone wins ????
danpost danpost

2013/3/3

#
Try it after removing the static qualifier for the GreenfootSound object (and the methods controlling it). Whether hat fixes it or not, the static qualifier is not neccessary as you will only have one Schlachtfeld world at a time.
Prish950 Prish950

2013/3/3

#
i fixed it :D Thanks so much :D
You need to login to post a reply.