I want my player to make a sound when it moves, and i have programmed this in. The problem is it loops the sound on top of itself, how can i make it play once and not play again until it has finished?
this is the code for the two methods i used:
private void moveControllable()
{
if(Greenfoot.isKeyDown("left")) {
move(-4);
play();
}
if(Greenfoot.isKeyDown("right")) {
move(4);
play();
}
if(Greenfoot.isKeyDown("up")) {
setLocation( getX(), getY()-4);
play();
}
if(Greenfoot.isKeyDown("down")) {
setLocation( getX(), getY()+4);
play();
}
}
private void play()
{
Greenfoot.playSound("pacman_chomp.wav");
};