Problem with Arrays
in
Programming Questions
•
10 months ago
I posted a few hours back about a sketch im working on where the user has a screen with a hardwood floor background and a camera and that once the user presses the space bar, the screen flashes and polaroids appear on the screen. So far everything works. Now the issue is if I want to create an array to make more than one polaroid appear. I would have about 9 set polaroids and the user would just press the space bar nine times until all pictures are visible on the screen.
Here's what I've got so far (picture.jpg is my polaroid picture)
float bx;
float by;
boolean overBox = false;
boolean locked = false;
boolean spacebarHasBeenPressed = false;
boolean flash = false;
float xOffset = 0.0;
float yOffset = 0.0;
PImage picture;//polaroids
PImage bg;//hardwoodfloor
PImage pcam;//camera
void setup()
{
size(900, 650);
bx = width/2.0;
by = height/2.0;
rectMode(RADIUS);
picture = loadImage("picture.jpg");
bg = loadImage("hardwood.jpg");
pcam = loadImage("pcam.png");
}
void draw()
{
background(bg);
image (pcam, 45, 330);
if(spacebarHasBeenPressed)
image (picture, bx, by);
if (mouseX > bx-0 && mouseX < bx+140 &&
mouseY > by-0 && mouseY < by+160) {
overBox = true;
if(!locked) {
}
} else {
overBox = false;
}
}
//Press spacebar to activate camera flash and get polaroid
void keyPressed() {
if (key == ' '){
spacebarHasBeenPressed = true;
flash = true;
noStroke();
fill(255);
rect(0,0,width,height);
}
}
//release spacebar to clear flash
void keyReleased(){
flash = false;
background(bg);
}
//click and drag polaroids
void mousePressed() {
if(overBox) {
locked = true;
} else {
locked = false;
}
xOffset = mouseX-bx;
yOffset = mouseY-by;
}
void mouseDragged() {
if(locked) {
bx = mouseX-xOffset;
by = mouseY-yOffset;
}
}
void mouseReleased() {
locked = false;
}
1