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

2017/2/12

Play sound when an object touch another.

LaurentiuRohan LaurentiuRohan

2017/2/12

#
Hy to all , is that possible to make greenfoot play a soudn only if one actor touches another one. I want to make a kind of quiz game . Player have to move a character to left or right where there are 2 boxes , with "true" or "false", if he wrongs I want play a sound, if he is right , then play another .
danpost danpost

2017/2/12

#
LaurentiuRohan wrote...
Hy to all , is that possible to make greenfoot play a soudn only if one actor touches another one. I want to make a kind of quiz game . Player have to move a character to left or right where there are 2 boxes , with "true" or "false", if he wrongs I want play a sound, if he is right , then play another .
Yes. It is quite possible. You will have to show what you might have tried, however, before we can fix your code.
Nosson1459 Nosson1459

2017/2/12

#
You can do:
1
2
3
4
5
6
7
8
9
10
GreenfootSound trueSound = new GreenfootSound(/* true sound file name */);
GreenfootSound falseSound = new GreenfootSound(/* false sound file name */);
if (isTouching(TrueButton.class)) // you need to use the name for your true actor
{
    trueSound.play();
}
else if (isTouching(FalseButton.class)) // you need to use the name for your false actor
{
    falseSound.play();
}
danpost danpost

2017/2/12

#
Nosson1459 wrote...
You can do: < Code Omitted >
Lines 1 and 2 in the code provided by Nosson1459 must be declared outside of the method; otherwise, a new sound will be created and played for each act cycle that the actor is touching the button.
You need to login to post a reply.