Need help with completing a part of my sketch
in
Programming Questions
•
10 months ago
I have a sketch that I'm working on and I can't go further without fixing this problem.
The function of the sketch is that there will be a camera on the corner and when you press the space bar, the screen will flash and polaroids will appear and accumulate on the screen. Once the polaroid shows up, users can drag them around on the screen and place them however they want to. I am able to make the polaroid appear on my sketch but only if I hold it down. What would I have to do to be able to just press the spacebar and make it draw a fixed polaroid?
this is my code so far
float bx;
float by;
boolean flash = false;
boolean overBox = false;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;
PImage picture;
PImage bg;
void setup()
{
size(900, 650);
bx = width/2.0;
by = height/2.0;
rectMode(RADIUS);
picture = loadImage("picture.jpg");
bg = loadImage("hardwood.jpg");
}
void draw()
{
background(bg);
if (mouseX > bx-0 && mouseX < bx+140 &&
mouseY > by-0 && mouseY < by+160) {
overBox = true;
if(!locked) {
}
} else {
overBox = false;
}
// Draw the box
}
void keyPressed() {
if (key == ' '){
image (picture, bx, by);
}
}
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