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

2020/12/6

Bad quality/saturated sound

Gbasire Gbasire

2020/12/6

#
hello, so in my "Trash Pokemon" game, I started to add some sound effects. They work ok, but the sound begins to be more saturated, the more it is played, which is really strange. for example. If I attack the enemy, the sound of the attack will play. But if I attack the enemy a second time, the sound will be like ear rape. Any idea of what is happening ? (the code is a simple Greenfoot.playSound) thanks !
danpost danpost

2020/12/6

#
Each time Greenfoot.playSound is called, a new GreenfootSound object is created (internally). So, you are creating a bunch of them. If you create one instance yourself and only play it, you will not have that issue. Add a field to hold the instance:
1
2
// example
private GreenfootSound sound = new GreenfootSound("sound.wav");
Then, to play, use:
1
sound.play();
Gbasire Gbasire

2020/12/6

#
I've done it, but the sound stays the same, it sounds well the first time and then it's strange
danpost danpost

2020/12/6

#
Gbasire wrote...
I've done it, but the sound stays the same, it sounds well the first time and then it's strange
Try changing:
1
2
3
4
5
sound.play()
 
// to
 
if (sound.isPlaying() == false) sound.play();
Gbasire Gbasire

2020/12/6

#
It doesn't seem to change, sadly.
You need to login to post a reply.