【问题标题】:Can't add image in Phaser 2.3.0无法在 Phaser 2.3.0 中添加图像
【发布时间】:2015-09-18 10:20:51
【问题描述】:

我正在尝试将图像添加到我的画布,但出现以下错误:

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');       
    }

};

【问题讨论】:

    标签: javascript html canvas phaser-framework


    【解决方案1】:

    this.add.image('block',100,255); 应该是this.add.image(100, 255, 'block'); - 参数顺序确实很重要,当方法接收到字符串而不是数字时,事情自然不会起作用。在这种情况下,您有 x、y 和图像的键。

    【讨论】:

    • 很高兴能帮上忙 :)
    【解决方案2】:

    添加图片this.add.image(x,y,'key');或者你可以使用像this.add.sprite(x,y,'key');这样的'sprite'

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2022-10-13
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 2014-04-11
      • 2016-11-09
      • 2019-04-07
      相关资源
      最近更新 更多