We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Using 2 buttons to go to the next screen
Page Index Toggle Pages: 1
Using 2 buttons to go to the next screen (Read 552 times)
Using 2 buttons to go to the next screen
Jan 8th, 2010, 1:55am
 
Hello,

Hard to explain, but here's the code 1st:

Code:
import gifAnimation.*;
import ddf.minim.*;

Minim minim;
AudioSnippet songR;
AudioSnippet songL;

int albumSize = 3;
int albumsize = 30;
int selectedPhoto = 0;
int selected = 0;
PImage[] photoAlbum;
PImage[] photo;
int timer;
Gif loopingGif;
int toestand = '1';

void setup() {
 photo = new PImage[albumsize];
 photoAlbum = new PImage[albumSize];
  size(1024, 768);

 
 photoAlbum[0] = loadImage("1.png");
 photoAlbum[1] = loadImage("2.png");
 photoAlbum[2] = loadImage("3.png");
 
 for(int i = 0;i<albumsize;i++){
 photo[i] = loadImage((i+1)+".jpg");
 }
 
 frameRate(3);
 loopingGif = new Gif(this, "LoadScreen.gif");
 loopingGif.loop();
 timer = 0;
 imageMode(CENTER);
 
 minim = new Minim(this);
 songR = minim.loadSnippet("rechts.wav");
 songL = minim.loadSnippet("links.wav");
}

void draw() {
 timer++;
 image(loopingGif, width/2, height/2);
 if(timer>=15){
     switch (toestand){
     case '1':
       if (photoAlbum[selectedPhoto] != null) {
       image(photoAlbum[selectedPhoto], width/2, height/2);
       }
     break;
     
     case '2':
       if (photo[selected] != null) {
       image(photo[selected], width/2, height/2);
       }
     break;
     }
 }
}  

void keyReleased() {
 if(key ==',') {
   songR.play();
   songR.rewind();
   if(selectedPhoto < 1) {
     selectedPhoto = photoAlbum.length - 1;
   } else {
     selectedPhoto--;
   }
 }
 if(key=='m') {
   int toestand ='2';
   println(selected);
 }
 if (key == '.') {
   songL.play();
   songL.rewind();
   if(selectedPhoto > photoAlbum.length - 2){
     selectedPhoto = 0;
   } else {
     selectedPhoto++;
   }
 }
   println(selectedPhoto);
   if (key ==',') {
         if(selected < 1) {
           selected = photo.length - 1;
         }
         else {
           selected--;
         }
       }
       if (key =='.') {
         if(selected > photo.length - 2) {
           selected = 0;
         } else {
           selected++;
         }
       }
       
 }
}



Don't mind the looping gif, because thats not important right now, but I've got a question about using 2 buttons at the same time to go somewhere. As you can see, there are already 2 keys declared to do something. , is used to go to the previous picture and . is declared to go to the next picture. But now I'd like to press . and , at the same time so that they go to another loop of pictures. (That's what Code:
  for(int i = 0;i<albumsize;i++){
 photo[i] = loadImage((i+1)+".jpg");
 }
is for. It's the other loop.)
If i do if (key =='.' && key==',') it just doesn't work. It does nothing. Can someone help me?

Thanks in advance
Re: Using 2 buttons to go to the next screen
Reply #1 - Jan 8th, 2010, 3:01am
 
One option is to use booleans - update these as the keys are pressed/released and then test against the value of the booleans, not the keys.

See here for an example...
Page Index Toggle Pages: 1