【问题标题】:Button in Phaser doesn't workPhaser 中的按钮不起作用
【发布时间】:2015-07-05 05:21:10
【问题描述】:

我有一个代码,只是一个通过 Phaser 创建的按钮:

//---------------------------------Boot
module.exports = {

 init: function() {
    closeButton = game.add.button(w/1.47, h/1.272, 'close', this.closeProfile, this);
    closeButton.fixedToCamera = true;
    closeButton.inputEnabled = true;
 },

 closeProfile: function() {
    alert('asd')
    close.key = 'img/profile/closePress.png';
 }
};

Module.exports - 这是 Browserify

在主文件中还有一段代码:

 //---------------------------------Main
 window.game = new Phaser.Game((h > w) ? h : w, (h > w) ? w : h, Phaser.CANVAS, 'game', {render:render});

var ship;
var cursors;
var sun1;
var rc;
var space;

var profile;
var closeButton, holdLeft, holdRight, avaProfile;

game.state.add('Boot', require('./states/boot.js'));
game.state.add('Play', require('./states/play.js'));
game.state.start('Boot');

而且按钮根本不调用函数。

【问题讨论】:

    标签: jquery button phaser-framework


    【解决方案1】:

    您好,我也是 Phaser 的新手,但我会尝试向按钮添加点击事件,如下所示。

    closeButton.inputEnabled = true;
    closeButton.events.onInputDown.add(onDown,this);
    function onDown(sprite,pointer){
         Some function code here;
     };
    

    说明:onDown是要调用的函数名,this关键字是指使用的输入法。然后在您传递精灵(或在本例中为单击的按钮)和使用​​的输入法(指针)的函数上。 祝你好运,希望能有所帮助。

    【讨论】:

    • 哦,刚刚注意到这个问题很老了,对不起,如果你很久以前就已经得到了答案,祝你好运
    【解决方案2】:

    尝试使用类似的东西:

     var button;
     button = game.add.button(200, 200, 'button', functionName, game);
    

    并放入create函数中。 init 函数用于调整大小等。

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2015-07-21
      • 2019-02-17
      • 2011-12-02
      相关资源
      最近更新 更多