Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Childrens game

$
0
0

Hi I've made this small game, when a letter is pressed its displayed on screen as an image and a sound plays. When I run the code and press a letter it shows the letter and plays the sound, but when I press the letter again it displays the letter but doesn't play the sound. I've tried using .rewind(); and what happens after that it first time I press a letter it plays the sound and displays the letter, and if I press the same letter again it displays the letter and when i release the key it plays the sound :S.

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer ha;
AudioPlayer sh;
AudioPlayer no;
AudioPlayer ra;
AudioPlayer ba;
AudioPlayer lh;

PImage[] letters = new PImage[6];

void setup() {
  size(400, 400);
  background(0);

  minim = new Minim(this);
  ha = minim.loadFile("0.mp3");
  sh = minim.loadFile("1.mp3");
  no = minim.loadFile("2.mp3");
  ra = minim.loadFile("3.mp3");
  ba = minim.loadFile("4.mp3");
  lh = minim.loadFile("5.mp3");

  imageMode(CENTER);

  for (int i = 0; i<letters.length; i++) {
    letters[i] = loadImage(+i+".jpg");
  }
}
void draw() {
  background(0);
  if ((keyPressed == true)&&(key == 'h')) {
    image(letters[0], width/2, height/2, 200, 200);
    ha.play();
  }
  if ((keyPressed == true)&&(key == 's')) {
    image(letters[1], width/2, height/2, 200, 200);
    sh.play();
  }
  if ((keyPressed == true)&&(key == 'n')) {
    image(letters[2], width/2, height/2, 200, 200);
    no.play();
  }
  if ((keyPressed == true)&&(key == 'r')) {
    image(letters[3], width/2, height/2, 200, 200);
    ra.play();
  }
  if ((keyPressed == true)&&(key == 'b')) {
    image(letters[4], width/2, height/2, 200, 200);
    ba.play();
  }
  if ((keyPressed == true)&&(key == 'l')) {
    image(letters[5], width/2, height/2, 200, 200);
    lh.play();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles