无法在 Phaser 2.3.0 中添加图像
Can't add image in Phaser 2.3.0
我正在尝试向我的 canvas 添加图像,但出现以下错误:
Uncaught TypeError: Cannot read property 'hasLoaded' of undefined
它说错误来自这一行:
this.add.image('block',100,255);
index.html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Camera Learning</title>
<script src="js/phaser.min.js"></script>
<script src="js/states/boot.js"></script>
</head>
<body>
<script>
(function(){
var game = new Phaser.Game(450, 510, Phaser.AUTO, 'game');
game.state.add('boot', boot);
game.state.start('boot');
})();
</script>
</body>
</html>
boot.js:
boot = function(game){
console.log("%cStarting my awesome game", "color:white; background:red");
};
boot.prototype = {
preload: function(){
this.load.image('block','./res/borderblock.png');
},
create: function(){
console.log('adding');
this.add.image('block',100,255);
console.log('added');
}
};
this.add.image('block',100,255);
应该是 this.add.image(100, 255, 'block');
- 参数顺序很重要,当方法接收到字符串而不是数字时,事情自然就不起作用了。在这种情况下,您有 x、y 和图像的密钥。
要添加图像 this.add.image(x,y,'key');
,或者您可以使用 'sprite',例如 this.add.sprite(x,y,'key');
我正在尝试向我的 canvas 添加图像,但出现以下错误:
Uncaught TypeError: Cannot read property 'hasLoaded' of undefined
它说错误来自这一行:
this.add.image('block',100,255);
index.html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Camera Learning</title>
<script src="js/phaser.min.js"></script>
<script src="js/states/boot.js"></script>
</head>
<body>
<script>
(function(){
var game = new Phaser.Game(450, 510, Phaser.AUTO, 'game');
game.state.add('boot', boot);
game.state.start('boot');
})();
</script>
</body>
</html>
boot.js:
boot = function(game){
console.log("%cStarting my awesome game", "color:white; background:red");
};
boot.prototype = {
preload: function(){
this.load.image('block','./res/borderblock.png');
},
create: function(){
console.log('adding');
this.add.image('block',100,255);
console.log('added');
}
};
this.add.image('block',100,255);
应该是 this.add.image(100, 255, 'block');
- 参数顺序很重要,当方法接收到字符串而不是数字时,事情自然就不起作用了。在这种情况下,您有 x、y 和图像的密钥。
要添加图像 this.add.image(x,y,'key');
,或者您可以使用 'sprite',例如 this.add.sprite(x,y,'key');