We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to be able to display a message like "Game Over" or "You win" to the user.
Ideally, I would just use a simple alert("You Win!")
. However, because of this bug, I cannot do that.
What is the easiest, most "p5.js way" to be able to display a message like "Game Over" to the user that is not an alert()
or confirm()
, prompt()
etc. ?
Answers
you can make a new state and say background(0);
and text("......".....
when mousePressed say state=GAME; again
@Chrisir, thanks! Yes that seems to definitely be possible, but ideally I would want something easier for my students to use. I suppose I could wrap it in a custom function...
Seems like the issue is that in Chrome/Chromium based browsers, KeyboardEvent's onkeyup() fails to trigger somehow when a modal window action like alert(), confirm() & prompt() is active.
In p5.js, that KeyboardEvent is bound to p5.prototype._onkeypress():
https://GitHub.com/processing/p5.js/blob/master/src/events/keyboard.js#L252
It is inside that callback that the closure object variable downKeys have its keys assigned to
false
:downKeys[e.which] = false;
My idea for a fix is to forcibly invoke p5.prototype._onblur() after each modal window action:
This way downKeys is emptied and keyIsDown() returns
false
for all keys:@GoToLoop, that sounds like an awesome idea, it would be amazing if you could make a pull request for that!
I can't b/c I was personally barred to ever lay a single character in there! 8-}
LOL, maybe I'll do that this weekend.
I believe that by simply invoking _onblur() should be able to reach p5.prototype._onblur(). O:-)
@jonl, here's your online example "fixed": ;) http://JSBin.com/tuzarutone/1/edit?html,js,output
I've just added _onblur() after alert():
Yuck. Alert() is really ugly. Trying to render text on a canvas is painful. A more modern approach is to have a DOM element that is displayed over the top of the canvas. There are scripts already out there that implement modal windows like this that could simplify things for your students, but working with DOM elements is a good skill to have, assuming this is relevant to the course you're running...