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

2012/5/19

How to loop sound, but only when the sound finished.

TechWebLock TechWebLock

2012/5/19

#
Hi, I am trying to make an sound file in an actor loop when it has finished playing.
gp1 = new GreenfootSound("goodplane.wav");
gp1.playLoop();  
that is currently what I have but ofcourse it just constantly loads and loops the sound file constantly making the sound play. How can I fix this?
danpost danpost

2012/5/19

#
The easiest way is by putting the GreenfootSound object in an instance field (after the Actor class declaration statement, or header), which would only involve moving your line 1 above outside of the method. Then, within the method, use
if (!gp1.isPlaying()) gp1.play();
TechWebLock TechWebLock

2012/5/19

#
Ok you have lost me there, do I need to put this into a new "void"?
danpost danpost

2012/5/19

#
I was suggesting it be just a seperate statement within the act() method; although you could create a new method with this one statement and call it from act with something like 'checkSound();', which is pointless (other than slightly making your act method cleaner).
davmac davmac

2012/5/20

#
TechWebLock:
Ok you have lost me there, do I need to put this into a new "void"?
A what now? They're called methods. 'void' is just the return type! :)
You need to login to post a reply.