我是移相器的新手,现在我使用移相器v.2.0.7。我想要做的是使一个Sprite处理触摸事件。
如何附加onTap
到精灵对象?
我知道可以使用进行触摸事件sprite_obj.events.onInputDown
,但是我仍然使用了onInputUp
这两种方法,因为当在后面触发了popup / modal(alert)时onInputDown
,您需要单击两次以使事件侦听器再次工作。(我对此问题的个人解决方法是使用inInputUp。)
我尝试过的另一件事是添加onTap
到我的canvas对象上,canvas.input.onTap.add
我认为这不适合实现我的目标。是的,它现在可以处理触摸事件,但是问题是我想将触摸事件仅限制在画布上的精灵图像上,而不是整个画布上。
有人能帮我吗。谢谢。
首先需要启用Sprite进行输入:
sprite.inputEnabled = true;
然后,您可以侦听Sprite涉及输入时调度的任何事件,例如:
sprite.events.onInputDown.add(onDown, this);
...
function onDown(sprite, pointer) {
// do something wonderful here
}
向回调发送2个参数:导致输入事件的Sprite和Pointer(如在多输入系统中,它可能经常变化)
指针具有许多您可以访问的属性,例如放置时间,移动历史记录等。有关详细信息,请参见指针文档。
Sprite有很多事件,但是这些是与Input相关的事件(这是直接从Phaser源代码中提取的):
/**
* @property {Phaser.Signal} onInputOver - This signal is dispatched if the parent is inputEnabled and receives an over event from a Pointer.
* @default null
*/
this.onInputOver = null;
/**
* @property {Phaser.Signal} onInputOut - This signal is dispatched if the parent is inputEnabled and receives an out event from a Pointer.
* @default null
*/
this.onInputOut = null;
/**
* @property {Phaser.Signal} onInputDown - This signal is dispatched if the parent is inputEnabled and receives a down event from a Pointer.
* @default null
*/
this.onInputDown = null;
/**
* @property {Phaser.Signal} onInputUp - This signal is dispatched if the parent is inputEnabled and receives an up event from a Pointer.
* @default null
*/
this.onInputUp = null;
/**
* @property {Phaser.Signal} onDragStart - This signal is dispatched if the parent is inputEnabled and receives a drag start event from a Pointer.
* @default null
*/
this.onDragStart = null;
/**
* @property {Phaser.Signal} onDragStop - This signal is dispatched if the parent is inputEnabled and receives a drag stop event from a Pointer.
* @default null
*/
this.onDragStop = null;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句