canvas画背景的一个问题
var can1; var can2; var ctx1; var ctr2; var lastTime; var daltaTime; var canWidth; var canHeight; var bgPic = new Image(); document.body.onload = game; function game(){ init(); lastTime = Date.now(); daltaTime = 0; //gameloop(); } function init(){ can1 = document.getElementById("canvas1"); ctx1 = can1.getContext('2d'); can2 = document.getElementById("canvas2"); ctx2 = can2.getContext('2d'); bgPic.src = "./src/background.jpg"; canWidth = can1.width; canHeight = can1.height; ctx2.drawImage(bgPic, 0, 0, canWidth, canHeight); }
我想在调用init方法的时候画,为什么会画不出来