//Also where I used mouse interaction for this assignment.
canvas.addEventListener('mousemove',function(event){
if(mouseClicked == false)
{
if((event.y-canvasBox.top)>=(4*cH/5))
{
canIClick=true;
start=new Date();
mouse.x = event.x-canvasBox.left;
circle1.x = mouse.x;
mouse.y = event.y-canvasBox.top;
circle1.y = mouse.y;
circle1.render();
}
else{
canIClick=false;
}
}
})
canvas.addEventListener("mouseup",function(event){
if(mouseClicked == false&&canIClick==true)
{
if((event.y-canvasBox.top)>=(4*cH/5))
{
mouseClicked = true;
mouse.x = event.x-canvasBox.left;
circle1.x = mouse.x;
mouse.y = event.y-canvasBox.top;
circle1.y = mouse.y;
circle1.render();
circle2.x = circle1.x;
circle2.y = circle1.y;
end = new Date();
timeDifference = end - start;
pokeBalls.push(circle2);
if (timeDifference >= timeLimit) {
pokeBalls[pokeBalls.length-1].dY=-20;
timeDifference=100;
power.value=timeDifference;
}
else
{
pokeBalls[pokeBalls.length-1].dY=-10-(timeDifference/(timeLimit/10));
timeDifference=timeDifference/((timeLimit/1000)*10);
power.value=timeDifference;
}
//circle2.update();
//alert(event.x+""+event.y);
}
}
})
我想将此代码切换为mouseDown,它也会在边界内触发每一定的秒数((event.y-canvasBox.top)> =(4 * cH / 5))(使用setInterval)在mouseClicked结束之前,用户不应该再单击它。问题是,如果我快速单击同一位置,它不会获得新的开始时间。由于mousemove不会触发也不会更新。