我刚刚开始使用 createjs,但遇到了这个菜鸟问题。使用 PreloaderJS 预加载图像后,我无法显示图像。我的代码:
<html>
<head>
<script src="https://code.createjs.com/easeljs-0.8.0.min.js"></script>
<script src="https://code.createjs.com/preloadjs-0.6.0.min.js"></script>
<script>
var queue, bg;
var stage;
function init(){
stage = new createjs.Stage("demoCanvas");
queue=new createjs.LoadQueue(true);
queue.on("complete", handleComplete, this);
queue.loadFile({id:"background", src:"http://localhost/img/mainGameBG.png"});
queue.load();
}
function handleComplete(event){
bg = queue.getResult("background");
stage.addChild(bg); //this where console gives red error in chrome
//document.body.appendChild(bg); //this code works so imageurl is correct
stage.update();
}
</script>
</head>
<body onload="init();">
<canvas id="demoCanvas", width="1000" height="700"></canvas>
</body>
错误信息: 未捕获 InvalidStateError:无法在“EventTarget”上执行“dispatchEvent”:提供的事件为 null。
最佳答案
您必须创建一个新的位图
并将其添加到舞台中:
bitmap = new createjs.Bitmap(queue.getResult("background"));
stage.addChild(bitmap);
关于javascript - 使用 PreloaderJS 未定义 stage.update(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29693983/