我正在使用easlejs+phonegap开发HTML5游戏,但是每次在画布上点击/触摸/mousedown时屏幕会闪烁。
下面是我为测试此问题而创建的非常简单的代码,以查看它是否与easlejs相关。从代码中可以看出,这与easlejs无关,只是一个html5/phonegap问题。
您可以看到我还尝试了no select CSS样式,但没有成功。
<!doctype html>
<html>
<head>
<title></title>
<style type="text/css">
#canvas
{
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
}
</style>
</head>
<body>
<canvas id="canvas" width="320" height="480"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
canvas.addEventListener("mousedown", function(e)
{
var ctx = canvas.getContext("2d");
var x = Math.random() * 320;
var y = Math.random() * 480;
var w = Math.random() * 100;
var h = Math.random() * 100;
ctx.fillStyle = "#FF0000";
ctx.fillRect(x,y,w,h);
}, false);
</script>
</body>
</html>