I am making a js game with a pause button. The button works fine, however if my mouse enters the button, leaves, and then clicks, the effect is triggered. Here is my code:
document.onmousemove=function(mouse){
mouseX=mouse.clientX-8;
mouseY=mouse.clientY-8;
}
//some time later in code
if(mouseX > Img.pause.x && mouseX < Img.pause.x+Img.pause.width && mouseY>Img.pause.y&& mouseY<Img.pause.y+Img.pause.height){//checked if mouse in button
document.getElementById('ctx').style.cursor="pointer";
document.onclick=function(){
pause=true;//if mouse in button AND it clicks
}
}
else{
document.getElementById('ctx').style.cursor="default";
}
The issue is that the mouse doesn't have to be in the button, it just has to have been in it for some time. How can I make this so that the mouse has to be inside AND click?