HTML body 部分代码:
<body>
<div class = "all_bg">
<div id = "allcanvas">
<canvas id = "canvas1" width = "800" height = "600">
</canvas>
<canvas id="canvas2" width="800" height = "600">
</canvas>
</div>
</div>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/commonFunctions.js"></script>
</body>
</html>
JS 代码:
var can1,can2;
var ctx1,ctx2;
function game()
{
init();
gameloop();
}
function init()
{
can1 = document.getElementById("canvas1");
ctx1 = can1.getContext(); //fishes dust UI circle
can2 = document.getElementById("canvas2");
ctx2 = can2.getContext(); //background ane fruits
}
function gameloop()
{
window.requestAnimFrame(gameloop);
console.log("loop");
}
兄弟 getContext('2d') 这里面要有参数
我前面加了“2d”,也出不来loop啊
document.body.onload = game; 我猜少了这句