Phaser JS - 按住按钮单击,将鼠标移开,然后放开单击触发 onMouseUp

Phaser JS - Holding click on button, moving mouse away, and letting go of click triggers onMouseUp

我正在学习 Phaser,并使用基本按钮进行练习。

例如,Phaser 按钮示例 right here

但是,我注意到,如果您按住鼠标并单击 Phaser 按钮,将鼠标移离该按钮,然后松开鼠标单击,Phaser 按钮仍会激活,就好像鼠标就在上面一样顶一下。

您也可以尝试按住鼠标单击移相器按钮,然后将鼠标移出框架。 Phaser 按钮也将激活。

我不确定这是否是 Phaser 中按钮的默认行为,但它不适用于其他 JS 游戏库/引擎,例如 Cocos 2D JS。

到目前为止,我已经尝试了以下方法:

这是我的代码:

this.playButton = this.game.add.button(this.game.world.centerX - 100, this.game.world.centerY + 230, 'ui', this.actionOnClick, this, 'ui_btn_play_U.png', 'ui_btn_play_U.png', 'ui_btn_play_D.png', 'ui_btn_play_U.png');
this.playButton.onInputUp.add(this.startGameplay, this);

actionOnClick() {

}

startGameplay() {

    this.clickButton();
    this.bgm.stop();
    var slideOut = Phaser.Plugin.StateTransition.Out.SlideTop;
    slideOut.duration = 1000;

    var slideIn = Phaser.Plugin.StateTransition.In.SlideTop;
    slideIn.duration = 1000;

    this.game.state.start('gameplay' , slideOut );

}

我该怎么做才能改变这种行为?

我以前遇到过这个问题,我就是这样解决的: 您需要组合三个事件 onInputDown、onInputUp 和 onInputOut。在伪代码中它会像下面这样:

myButton.clicked=false;
When myButton.onInputDown -> myButton.clicked=true
When myButton.onInputOut -> myButton.clicked= false
When myButton.onInputUp -> if (myButton.clicked) then do desired action