【问题标题】:How to create a Phaser button in Facebook instant games for a mobile device如何在移动设备的 Facebook 即时游戏中创建 Phaser 按钮
【发布时间】:2018-10-22 06:29:42
【问题描述】:

我正在尝试在移动设备上使用 Phaser 2 CE 创建一个按钮,但它不会触发,即使它在桌面上工作正常,整个代码将在 my github repository 但目前我只能显示如下代码中的图像

var game = new Phaser.Game(640, 480, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });

function preload () {

  game.load.image('logo', 'assets/phaser2.png');
  game.load.image("upArrow", "assets/up.png");

}

function create () {
  // Initialize player
  //player = game.add.sprite(20, 20, 'logo');
  game.device.desktop || addMobileInputs();    
}

function addMobileInputs() {
  upButton = game.add.sprite(40, 40, "upArrow");
  upButton.inputEnabled = !0;
  upButton.events.onInputDown.add(myHandler, this);
}

function myHandler() {
  alert("up");
}

function update() {

}

【问题讨论】:

    标签: facebook phaser-framework facebook-instant-games


    【解决方案1】:

    alert("...") 似乎没有触发,代码是正确的,因为如果你只是让你的精灵移动,它就会移动,例如下面的代码:

    var game = new Phaser.Game(640, 480, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
    var sprite;
    
    function  preload () {
      // This is equivalent to <https://examples.phaser.io/assets/>.
      this.load.image('dude', 'assets/sprites/phaser-dude.png');
    }
    
    function create() {
      sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dude');
      sprite.inputEnabled = true;
      sprite.events.onInputDown.add(myHandler, this);
    }
    
    function myHandler() {
      sprite.x += 10;
    }
    
    function update() {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多