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

2017/3/20

My background music is weird... Need Help

Zappib Zappib

2017/3/20

#
So when I added this code t my level1 world, it works fine the music plays but there is one thing that happens that I do not like. So when the music endds it does bot loop to the start and another thing is when i go to a new world, via teliports on my game, the music will not stop. I need some help with this please! thank you <3
public Level1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(5000, 700, 1); 
        backgroundMusic.playLoop();
        backgroundMusic.setVolume(40);
        prepare();
    }


    public void stopped()
    {
        backgroundMusic.pause();
    }

    public void started()
    {
        backgroundMusic.playLoop();
        backgroundMusic.setVolume(40);
    }
Super_Hippo Super_Hippo

2017/3/20

#
In the code given, there is nothing which could prevent it from looping. I don't think you did something wrong at this one, but you didn't show the line where you create the backgroundMusic object. Do you call 'play' on the backgroundMusic object from somewhere else? Is there some time without sound at the end of the sound file, so you think it is not looping although it finishes the silent part? For the other problem: The 'stopped' method is executed when either 'Greenfoot.stop()' was called or when someone presses 'Pause' (which itself probably just calls 'Greenfoot.stop()'. So it is not executed when you change the world. You have to call the 'stopped' method on your own when you change the world to stop the music.
Zappib Zappib

2017/3/20

#
Super_Hippo wrote...
In the code given, there is nothing which could prevent it from looping. I don't think you did something wrong at this one, but you didn't show the line where you create the backgroundMusic object. Do you call 'play' on the backgroundMusic object from somewhere else? Is there some time without sound at the end of the sound file, so you think it is not looping although it finishes the silent part? For the other problem: The 'stopped' method is executed when either 'Greenfoot.stop()' was called or when someone presses 'Pause' (which itself probably just calls 'Greenfoot.stop()'. So it is not executed when you change the world. You have to call the 'stopped' method on your own when you change the world to stop the music.
What I saw I did not know that I needed a backgrouondMusic object, how would I set up the backgroundMusic object? Is there a way that I can all that stop method when I go to another level/world? thank you for the reply <3
Super_Hippo Super_Hippo

2017/3/20

#
You have a backgroundMusic object already. I mean you use that variable and if you don't have it, it shouldn't compile. It depends from where you change the world.
//from the world
stopped();
Greenfoot.setWorld(......);


//from actor inside the world
getWorld().stopped();
Greenfoot.setWorld(......);

//in case the second one doesn't work
((WorldName) getWorld()).stopped();
Greenfoot.setWorld(......);
You need to login to post a reply.