本文介绍了如何在Facebook即时游戏中为移动设备创建“移相器"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在移动设备上使用Phaser 2 CE创建一个按钮,但是即使在台式机上也能正常工作,它也不会触发,整个代码将位于我的github仓库,但目前我只能像下面的代码所示显示图像
I am trying to create a button with Phaser 2 CE on a mobile device but it doesn't fires, even if it works fine on desktop, the entiere code will be on my github repository but for the moment i can just display an image like in the code bellow
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() {
}
推荐答案
alert("...")
似乎不会触发,并且代码是正确的,因为如果您仅移动精灵,它就会移动,例如像代码一样下方:
It seems that alert("...")
doesn't fire, and the code is correct because if you just make your sprite move, it moves, for example like the code below:
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() {
}
这篇关于如何在Facebook即时游戏中为移动设备创建“移相器"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!