How can I cause different events based on some text's position?

edited May 2016 in How To...

I have a story that is read by mouseWheel scrolling. At the some words, there could be events like as fading screen out, playing an audio while we are scrolling the text. How can i achieve this events based on the text position? I will be appreciate if you help me. This is the code i work on below;

String[] headlines = {
"Aniden yerimden fırladım ve üzerine atladım. Ayağım takıldı ve düşmemle birlikte kafamı yere çarptım.  Uyandığımda sırılsıklamdım",
};
String c="Please scroll the mouse wheel to read the story";

PFont f;
PFont f2;
float x;
int index = 0;

void setup() {
  size(800, 450);
  textAlign(CENTER);
  f = createFont("calibri", 16, true); 
  f2 = createFont("calibri", 10); 
  x = width;
}

void draw() {
  background(245);

  stroke(255, 200, 0);
  fill(255, 200, 0);
  rect(293, 164, 220, 20);

  textFont(f, 16);        
  fill(100, 100, 100);
  text(headlines[index], x, 180); 

  textFont(f2, 10);
  fill(70);
  text(c, 400, 400);

  stroke(255, 255, 255);
  fill(255, 255, 255);
  rect(500, 164, 400, 20);
  rect(0, 164, 293, 20);

  if (x < -textWidth(headlines[index])) {
    x = width; 
    index = (index + 1) % headlines.length;
  }
}

void mouseWheel(MouseEvent event) {
  x-=event.getCount();
}
Sign In or Register to comment.