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

2016/6/8

Stickman - Exercise 3.37

david_h david_h

2016/6/8

#
Hi, is there a recommended solution for getting the stickman to float when he hears a noise. I have done some searching on the internet, and some of the solutions look very complex. Thanks in advance.
danpost danpost

2016/6/8

#
If you do not have very many sound files and they are all fairly short, then I would suggest keeping a reference to all of them in a class array, like (let us say the code is in a 'MyWorld' class):
1
2
3
4
5
6
public static GreenfootSound[] sounds =
{
    new GreenfootSound("bump.wav"),
    new GreenfootSound("aw.wav"),
    new GreenfootSound("victory.wav")
};
Then:
1
MyWorld.sounds[0].play(); // plays 'bump.wav'
and:
1
if (MyWorld.sounds[2].isPlaying()) // checks if 'victory.wav' is playing
You need to login to post a reply.