Hello Forum,
I work with a beginning code class of teen-aged students. For the ones who struggle, I have a simple design project where they program a series of images (stop-motion type thinking) to move with mouseX and mouseY. I would like them also to be able to add a sound effect at different places with specific images. I am doing something like the code below but I would like the sound to just play once rather than looping when mouse hovers? And, I am assuming there are better ways to set up roll-over SFX - would love thoughts on how to make the sounds play once and other cool ways to simplify the loading of sound with roll-over images. Thanks!
//SOUND
import ddf.minim.*;
Minim minim;//audio context
AudioPlayer song1;
AudioPlayer song2;
AudioPlayer song3;
AudioPlayer song4;
PImage img1, img2, img3, img4;
//setup
void setup () {
size (670,237);
background (255);
img1 = loadImage("bird1.png");
img2 = loadImage("bird2.png");
img3 = loadImage("bird3.png");
img4 = loadImage("bird4.png");
}
//draw function that loops
void draw () {
//draw lines to divide quadrants
//upper left quadrant is red
if ((mouseX < 150) && mouseY > 0) {
image(img1, 0,0);
minim=new Minim(this);
song1=minim.loadFile("one.mp3",1000);
song1.play();
//upper right quadrant cyan
} else if ((mouseX < 250)&& (mouseY > 0)){
image(img2, 0,0);
minim=new Minim(this);
song2=minim.loadFile("two.mp3",1000);
song2.play();
//lower left quadrant gray
}else if ((mouseX < 340) && (mouseY >0)) {
image(img3, 0,0);
minim=new Minim(this);
song3=minim.loadFile("three.mp3",1000);
song3.play();
// lower right quadrant black
}else if ((mouseX < 440) && (mouseY > 0)){
image(img4,0,0);
minim=new Minim(this);
song4=minim.loadFile("four.mp3",1000);
song4.play();
}
}