javascript - How to wait for a click on canvas -


i put "pause" in program. basically, every time call wait() function, nothing should happen until click canvas.

drawrectangle(a,b,c,d) waitforclick() drawrectangle(e,f,g,h) 

the first rectangle drawn, , second 1 not drawn until click on canvas. thank help.

you may looking @ problem wrong way. it's not best idea halt program since want execution happen possible. 1 of big advantages javascript has awesome event api baked in it.

instead of making program wait/sleep, try using events:

drawrectangle(a, b, c, d); 

let's make function run when detect click events:

function customclickeventhandler(event) {   drawrectangle(e, f, g, h); } 

and finally, bind new function window's 'click' event. can choose dom element, not window.

window.addeventlistener('click', customonclickevent); 

documentation

events api: https://developer.mozilla.org/en/docs/web/api/event

follow link find out more 'addeventlistener' function: https://developer.mozilla.org/en-us/docs/web/api/eventtarget/addeventlistener

update

if want add multiple handlers, it's easy:

function eventhandler1(event) {   // something... }  function eventhandler2(event) {   // else... }  window.addeventhandler('click', eventhandler1); window.addeventhandler('click', eventhandler2); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -