2017-05-19 48 views
0

我正在使用Phaser,並使用基本按鈕進行練習。Phaser JS - 按住按鈕,將鼠標移開,然後放開鼠標點擊觸發器MENDUP

舉例來說,查看沒有比移相器按鈕示例right here更進一步。

不過,我注意到,如果你按住移相器按鈕,你的鼠標點擊,從按鈕移動鼠標走,放開你的鼠標點擊,移相器按鈕仍激活爲鼠標是正確的頂部的。

您也可以嘗試按住鼠標左鍵單擊Phaser按鈕,然後將鼠標移出框架。 Phaser按鈕也會激活。

我不確定這是Phaser中按鈕的默認行爲,但它不適用於其他JS遊戲庫/引擎,如Cocos 2D JS。

到目前爲止,我已經試過如下:

  • 設置按鈕激活onInputDown - 不是真的首選。
  • 設置另一個功能onInputUp - 不會改變行爲。

這裏是我的代碼:

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

} 

我能做些什麼來改變這種行爲?

回答

0

我面對這個問題很久以前,這就是我如何解決它: 您需要結合三個事件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 
+0

這幾乎是我幾天後做的。我希望有一個內置的解決方案,或者至少有一個不需要我基本上對兩個額外的功能。但是,謝謝你。 –