我正在尝试制作飘扬的小鸟,但是当我尝试将背景加载到画布上时,它什么也没做
attr
答案 0 :(得分:0)
我建议您将整个图像加载代码移至onload
处理程序中。这样,您可以确保在实际调用drawImage
之前已加载所有内容。另外,正如@Chris G所提到的,它是window.onload
,而不是window.onLoad
:
// draw images
window.onload = function(){
var cvs = document.getElementById("canvas");
var ctx = cvs.getContext("2d");
// load img
var bird = new Image();
bird.src = "img/bird.png";
var bg = new Image();
bg.src = "img/bg.png";
var fg = new Image();
fg.src = "img/fg.png";
var pipeNoord = new Image();
pipeNoord.src = "img/pipeNorth.png";
var pipeSouth = new Image();
pipeSouth.src = "img/pipeSouth.png";
ctx.drawImage(bg, 0, 0);
}