We are about to switch to a new forum software. Until then we have removed the registration on this forum.
String[] headlines = {
"1" ,
"2" ,
"3" ,
"4" ,
"5",
"6",
"7",
"8",
"9",
};
PFont f; // Global font variable
float x; // Horizontal location
int index = 0;
void setup() {
size(600,400);
rectMode(CENTER);
f = createFont( "Arial" ,20,true);
// Initialize headline midscreen
x = width/2;
}
void draw() {
if(index>=6){
index=0;
}
if(index<0){
index=6;
}
background(0);
fill(255);
// Display headline at x location
textFont(f,20);
textAlign (CENTER);
text(headlines[index],x,height-300,width/2,100);
text(headlines[index+1],x,height-200,width/2,100);
text(headlines[index+2],x,height-100,width/2,100);
if(keyPressed){
if (key=='a'){
index = (index + 1);
}
if (key=='s'){
index = (index - 1);
}
}
}
I am trying to make it cycle through the numbers by pressing either a or s for different directions.
The program should move them up 1 at a time, not sure why its doing what it does.
Cheers.
Answers
You don't describe exactly what is your problem, but I am suspecting it is related to what I describe in the Technical FAQ article I just wrote: Why is my mouse pressed code executed several times? B-)
Just replace mouse with key...