My p5 installation is all set up and running smoothly, but I've encountered an issue with the mousePressed() function (keyPressed() isn't working either). Here's the problematic part of the code:
//press play button
if (mouseX > 120 && mouseX < 480 && mouseY > 160 && mouseY < 220) {
playfill = 120;
inButtonP = true;
} else {
playfill = 0;
sharefill = 0;
settingsfill = 0;
inButtonP = false;
};
function mousePressed() {
if (inButtonP) {
playing = true;
println("pressed");
};
};
Here is the full code:
//is the game over?
var playing = false;
//speed at which the square will move
var speedx = 6;
var speedy = 4;
//setting square variables
var square = {
x : 300,
y : 200,
length : 80
};
//score
var score = 0;
//start + end background
var g = 120;
//start menu colour colChange
colChange = -3;
//transparency of buttons
var playfill = 0;
var sharefill = 0;
var settingsfill = 0;
var inButtonP = false;
function setup() {
createCanvas(600, 400);
}
function draw() {
//start screen
if (!(playing)) {
//background
background(221, g, 222);
//menu rectangle
stroke(255, 255, 255);
strokeWeight(5);
fill(0, 0, 0, 0);
rectMode(CENTER);
rect(300, 200, 500, 300, 50);
//menu text
textAlign(CENTER);
textSize(32);
text("THE WAITING GAME", 300, 120);
//play button
stroke(255, 255, 255);
strokeWeight(2);
fill(255, 255, 255, playfill);
rectMode(CENTER);
rect(300, 190, 360, 60);
textSize(20);
text("PLAY GAME", 300, 197);
// More content exists here.
};
// Main game section.
if (playing) {
// Additional content and logic present in this section.
};
}
I added some filler text for separation purposes. If needed, more information can be provided about the code.