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

2012/5/24

Music Problems

1
2
Denzien Denzien

2012/5/24

#
I am having problems with music, I am putting it in the act file of an actor so it doesn't contantly play, but when I use an mp3 file, it lags and crashes, then when a try to use a .wav file, it just play a kind of loud static sound intead of music, the only way to fix it is to put it in the world class, but then it plays all the time, not just when I click play, any help?
IsVarious IsVarious

2012/5/24

#
So one problem is that you're trying to put it in the "act()" method, so your code is being called over and over, because act is called over and over. Is it that your'e trying to add some background music to the game? at the start of a level, game what? Otherwise you can simply add a line to your world's constructor, so it calls the sound file once the level starts.
Denzien Denzien

2012/5/25

#
I want background music, but only playing once, from the moment I press go
erdelf erdelf

2012/5/25

#
this in world
public void started()
{
    Greenfoot.playSound("music.wav");
}
Denzien Denzien

2012/5/25

#
Ok great thanks alot (seems so simple...) One more Question though, how do I stop the sound when I stop it
erdelf erdelf

2012/5/25

#
You mean when it is over?
Denzien Denzien

2012/5/25

#
Or when I go into a new level
erdelf erdelf

2012/5/25

#
Do you make the new with a new world ?
Denzien Denzien

2012/5/25

#
yes, that and when I end the senario
erdelf erdelf

2012/5/25

#
In a new world it stops automatically.
Denzien Denzien

2012/5/25

#
Oh ok so how do I stop it when I just stop the senario EDIT: actually I just tested it, it doesn't end in a new world.
erdelf erdelf

2012/5/25

#
hm ok. So let's change it. This in world
GreenfootSound backgroundmusic = new GreenfootSound("test.wav");

public void started()
{
     backgroundmusic.play()
}
and this in the actor which changes world
if(backgroundmusic.isPlaying())
{
    backgroundmusic.stop
}
Denzien Denzien

2012/5/25

#
Hmm ok It will require a lot of fiddleing but ok. Thanks alot :)
Denzien Denzien

2012/5/25

#
It doesn't work because variables in the world class don't work in the class that creates the new world
erdelf erdelf

2012/5/25

#
You have to call the world
There are more replies on the next page.
1
2