如何在Phaser中获得activePointer压缩精灵的持续时间 [英] how to get activePointer pressed duration of sprite in Phaser

查看:81
本文介绍了如何在Phaser中获得activePointer压缩精灵的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

解决方案

在移相器3中类似

  function update(){
var duration = 0
if(this.input.activePointer.isDown){
duration ++;
}
}


I'm creating pinball game using Phaser Framework.

When the ball holder is pressed (please check attached screenshot so you have an idea what I mean ball holder), depending on the press speed, it should move the ball around the spiral channel. So now trying to detect the down pressed duration of the holder.

Here is my code:

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

So pointer.duration is not working and returns 0.

But game.input.activePointer.duration inside update() function is working and returns 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);
}

How can I make it work for specific item/sprite? Any ideas please?

解决方案

in phaser 3 something like

function update(){
 var duration = 0
 if( this.input.activePointer.isDown ){
  duration++;
 }
}

这篇关于如何在Phaser中获得activePointer压缩精灵的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆