[英]how to get activePointer pressed duration of sprite in Phaser
我正在使用Phaser Framework创建弹球游戏。
按下持球器时(请检查随附的屏幕截图,以便您了解我的意思是持球器),具体取决于按下速度,它将使球绕螺旋通道移动。 因此,现在尝试检测支架的按下时间。
这是我的代码:
var ballButton;
ballButton = game.add.sprite(196, 100, 'ballHolder');
ballButton.inputEnabled = true;
ballButton.events.onInputDown.add(inputDownAction, this);
function inputDownAction(ballButton, pointer) {
/* returns 0 */
console.log( pointer.duration);
}
因此, pointer.duration
无法正常工作并返回0
。
但是update()函数中的game.input.activePointer.duration
正在工作并返回持续时间。
if (game.input.activePointer.duration > 200 && game.input.activePointer.duration < 500){
console.log('first range '+game.input.activePointer.duration);
}else if(game.input.activePointer.duration > 500 && game.input.activePointer.duration < 700){
console.log('second range '+game.input.activePointer.duration);
}else if(game.input.activePointer.duration > 700){
console.log('third range '+game.input.activePointer.duration);
}
如何使它适用于特定的物品/精灵? 有什么想法吗?
在移相器3中,类似
function update(){
var duration = 0
if( this.input.activePointer.isDown ){
duration++;
}
}
您可以从场景中获取时间,并通过activePointer中的downTime进行计算。 因此,您可以尝试以下方法:
function update(time, delta){
console.log(time - window.game.input.activePointer.downTime);
}
我得出的结论是,当您要按下按键时获得持续时间时,这是最好的方法,因为activePointer(Phaser3)中不再有持续时间属性。 因此,此代码也适用于Phaser 3。
希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.