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

2021/11/16

i get a weird sound when i copy on greenfoot

siizwee siizwee

2021/11/16

#
public void changeimage() { if(isTouching(spieler.class) && Greenfoot.isKeyDown("E")) { if (getImage().equals(smallTree) == false) counter.add(1); setImage(smallTree); Greenfoot.playSound("pops.wav"); } this is the code and when i paste the sound on greenfoot i get a different sound from what i downloaded. Please can i get help to why the sound isnt working?
danpost danpost

2021/11/16

#
Use "E".equals(Greenfoot.getKey()) instead of Greenfoot.isKeyDown("E"). Currently, both conditions required to play sound can be true for multiple act steps. As such, a new pop sound will start on every act step until one or both of the conditions fail to be true. Another way to prevent this is to retain the sound in a field and use its reference to play the sound, so when asked to play the sound again it references the same sound object which would already be playing; it will just continue playing). However, once the sound stops, if both conditions are still true, it will play again. It will not at least play over top of another instance of the same sound as before, multiple times. Note that getKey only works once per act step. If used multiple times in the same step, only the first one will register any key. There is a way around that, if required.
siizwee siizwee

2021/11/19

#
thanks Dan!!!
You need to login to post a reply.