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

2016/2/11

I need code to run every 3 seconds

Hydrowarrior Hydrowarrior

2016/2/11

#
Im making a game where I would like a certain sound to run every 3 seconds. This is the code I would like to run every three seconds. Is there something I could stick in the public void act() to make this work? if(distance <= 200) { Ping.setVolume(100-(Math.round(distance/2))); Greenfoot.playSound("Ping.wav"); }
danpost danpost

2016/2/12

#
There are (1) omissions, (2) flaws and (3) peculiarities in the code you have supplied. First, what is distance, how is it controlled and should it be a factor in playing the sound -- or is the sound to play every 3 sconds, regardless? Second, you cannot control any aspect of a sound that you have no reference to (using 'Greenfoot.playSound' you cannot get a reference to the sound to control its volume). You need to create a GreenfootSound object and then set its volume and then play it. Finally, it appears you want the volume to increase as it approaches something (whatever distance is related to); then after it gets closer, the volume will start decreasing again. You will need to give a better explanation of what you are trying to do and supply more code before any decent help can be given.
You need to login to post a reply.