ImpactJS和HammerJS鼠标输入相互冲突

ImpactJS and HammerJS mouse input conflicts with one another

本文关键字:冲突 输入 鼠标 HammerJS ImpactJS      更新时间:2023-09-26

我正在使用ImpactJS引擎(http://impactjs.com/)创建一款游戏。这款游戏需要使用拖拽和滑动等手势。因此,HammerJS被集成到代码中。

在下面的代码片段中,当左键单击绑定为ig.input时,不会触发释放事件回调。

init : function() {
    // The onRelease() is triggered when this is commented out.
    //ig.input.bind( ig.KEY.MOUSE1, "click" );
    Hammer( this.canvas ).on( "dragup", this.onDragUp.bind( this ) );
    Hammer( this.canvas ).on( "dragdown", this.onDragDown.bind( this ) );
    Hammer( this.canvas ).on( "release", this.onRelease.bind( this ) );
},
onRelease : function() {
    alert( "Released!" );
}
onDragUp : function( event ) { 
    //No problem here.
}
onDragDown : function( event ) {
   //No problem here.
} 

这里有什么问题吗?谢谢。

这就解决了我的问题:

Hammer( this.canvas ).on( "dragup", this.onDragUp.bind( this ), {prevent_default: true} );
https://github.com/EightMedia/hammer.js/issues/538