问答详情
源自:2-1 绘制背景

为什么我的控制台打印不出loop?

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");

}


提问者:一起玩137 2018-05-24 11:22

个回答

  • 慕盖茨7304037
    2018-06-09 00:40:16
    已采纳

    兄弟 getContext('2d') 这里面要有参数


  • 洛雁菱
    2018-06-16 17:26:05

    我前面加了“2d”,也出不来loop啊


  • hjs9622
    2018-05-25 18:44:23

    document.body.onload = game; 我猜少了这句