mousePressed event executes before keyPressed
in
Programming Questions
•
8 months ago
Hi guys
This bug has seriously ruined my week. I'm trying to create an interactive leaderboard and in it are three arrays: 1 with images and 2 with integers that I wrote as strings. I'm trying to make a keyPressed event that'll make the numbers change with the images representing the teams as they go up or down the ladder and I have a mousePressed event to execute a loop to revert the window back to its original state.
My problem is when I try to run the code the keyPressed event doesn't execute and only does so after I click on the mouse. Then the images move but the string array doesn't loop back with the first set of images. I have included the code below...I know it is lengthy and trust I have been refractoring and shortening as I go. Right now what I would like help with is making sure the keyPressed event executes first and the the positions1 string array reverts back to its original position when the loop executes.
I have included my code below and am working on a Macbook Pro OSX Processing 2.0b7.
This bug has seriously ruined my week. I'm trying to create an interactive leaderboard and in it are three arrays: 1 with images and 2 with integers that I wrote as strings. I'm trying to make a keyPressed event that'll make the numbers change with the images representing the teams as they go up or down the ladder and I have a mousePressed event to execute a loop to revert the window back to its original state.
My problem is when I try to run the code the keyPressed event doesn't execute and only does so after I click on the mouse. Then the images move but the string array doesn't loop back with the first set of images. I have included the code below...I know it is lengthy and trust I have been refractoring and shortening as I go. Right now what I would like help with is making sure the keyPressed event executes first and the the positions1 string array reverts back to its original position when the loop executes.
I have included my code below and am working on a Macbook Pro OSX Processing 2.0b7.
- PImage[] images = new PImage[24];
- PImage img = new PImage();
- PImage quarterFinalWinners = new PImage();
- float damping = 0.1;
- PFont font;
- String[] positions1 = {"18", "26", "32", "45", "58", "56", "59", "61", "66", "69", "71", "85", "98", "100", "116", "133"};
- String[] positions2 = {"14", "19", "25", "30", "34", "45", "52", "69", "71", "72", "87", "84", "89", "105", "107", "110"};
- float x;
- float y;
- void setup() {
- noLoop();
- size(600, 1600);
- frameRate(60);
- smooth();
- font = loadFont("Calibri-Bold-48.vlw");
- textFont(font);
- frame.setResizable(true);
- for (int i = 0; i < images.length; i++) {
- images[i] = loadImage(i + ".png");
- }
- noLoop();
- }
- void draw() {
- background(0);
- image(images[0], 150, 50);
- image(images[1], 150, 110);
- image(images[2], 150, 170);
- image(images[3], 150, 230);
- image(images[4], 150, 290);
- image(images[5], 150, 350);
- image(images[6], 150, 410);
- image(images[7], 150, 470);
- image(images[8], 150, 530);
- image(images[9], 150, 590);
- image(images[10], 150, 650);
- image(images[11], 150, 710);
- image(images[12], 150, 770);
- image(images[13], 150, 830);
- image(images[14], 150, 890);
- image(images[15], 150, 950);
- text(positions1[0], 120, 125);
- text(positions1[1], 120, 185);
- text(positions1[2], 120, 245);
- text(positions1[3], 120, 305);
- text(positions1[4], 120, 365);
- text(positions1[5], 120, 425);
- text(positions1[6], 120, 485);
- text(positions1[7], 120, 545);
- text(positions1[8], 120, 605);
- text(positions1[9], 120, 665);
- text(positions1[10], 120, 725);
- text(positions1[11], 120, 785);
- text(positions1[12], 120, 845);
- text(positions1[13], 120, 905);
- text(positions1[14], 120, 965);
- text(positions1[15], 120, 1025);
- }
- void keyPressed () {
- if((key == 's') || (key == 'S')) {
- positions1 = positions2;
- }
- noLoop();
- image(images[10], 150, 290);
- image(images[19], 150, 50);
- image(images[17], 150, 230);
- image(images[2], 150, 110);
- image(images[22], 150, 410);
- image(images[20], 150, 470);
- image(images[16], 150, 650);
- image(images[6], 150, 350);
- image(images[7], 150, 590);
- image(images[18], 150, 770);
- image(images[21], 150, 170);
- image(images[12], 150, 830);
- image(images[13], 150, 530);
- image(images[23], 150, 950);
- }
- void mousePressed () {
- if (mousePressed) {
- positions2 = positions1;
- }
- loop();
- }
1