Phaser 3 多指针事件合二为一
Phaser 3 Multiple Pointer Events in one
我目前有两个指针事件,它们基本上做同样的事情:
gameState.idle.on('pointerout', function(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
});
gameState.idle.on('pointerup', function(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
});
有什么办法可以把这两者结合起来吗?例如,我尝试了 gameState.idle.on('pointerup, pointerout', function(){});
,但显然没有用。
不,这是不可能的,但是你可以只写一个处理程序函数并将它用于both/multiple事件.
像这样:
...
function mouseHandler(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
}
function create() {
...
gameState.idle.on('pointerout', mouseHandler);
gameState.idle.on('pointerup', mouseHandler);
...
}
Important: not parentheses after mouseHandler
, in the event handler.
我目前有两个指针事件,它们基本上做同样的事情:
gameState.idle.on('pointerout', function(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
});
gameState.idle.on('pointerup', function(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
});
有什么办法可以把这两者结合起来吗?例如,我尝试了 gameState.idle.on('pointerup, pointerout', function(){});
,但显然没有用。
不,这是不可能的,但是你可以只写一个处理程序函数并将它用于both/multiple事件.
像这样:
...
function mouseHandler(){
scene.sys.canvas.style.cursor = 'default';
gameState.pet_cursor.alpha = 0;
}
function create() {
...
gameState.idle.on('pointerout', mouseHandler);
gameState.idle.on('pointerup', mouseHandler);
...
}
Important: not parentheses after
mouseHandler
, in the event handler.