I'm encountering a problem trying to hide a custom button I made using p5.js
:
var quit_button;
var pause = false;
function keyPressed() {
if (keyCode == '80') { // If p is pressed on the keyboard
if (pause === true) {
quit_button.hide()
pause = false;
} else {
pause = true;
}
}
}
function restart() {
quit_button.hide() // This doesn't seem to work
pause = false;
setup()
}
function setup() { // Initial screen setup
createCanvas(600, 400);
}
function draw() {
background('#fae'); // A fresh canvas is created
if (pause === true) {
quit_button = createButton('quit')
quit_button.position(300,200)
quit_button.mousePressed(restart)
text("Game has been paused. Press P to resume.", 100, 100)
} else {
}
}
When running the code and hitting p
to pause my snake game, it indeed pauses as expected. However, when attempting to unpause by pressing p
again or by clicking 'quit', the quit
button remains visible.