Stings and Arrays, cycling through strings

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.

Tagged:

Answers

Sign In or Register to comment.