[phaser] Detect Double Click And LongPress updated_at: 2024-12-15 04:02

Detect Double Click And LongPress

예제 1

public create () {
  this.input.on('pointerdown', (pointer: any) => {
    this.pointerAct = 'pointerdown';

    this.confirmDoubleClick();

    this.longPressSettimeout = setTimeout(() => { // 0.5초간 누를경우 long press 로 인식

    }, 500);

  });

  this.input.on('pointermove', (pointer: any) => {
  })

  this.input.on('pointerup', (pointer: any) => {
    this.pointerAct = 'pointerup';
    clearTimeout(this.longPressSettimeout);
  })

}

private confirmDoubleClick() {
  if (!this.secondClick) { // this.secondClick = false;
    this.secondClick = true;
    this.time.delayedCall(300, () => { // 300 utime
      this.secondClick = false;
    });
    return false;
  }
  return true;
}

예제 2

private handler(shape: any) {
  shape.setInteractive({ draggable: true })
    .on('dragstart', (pointer: any, dragX: number, dragY: number) => {
      this.hanlderStatus = 'dragstart';
      this.confirmDoubleClick();

      this.longPressSettimeout = setTimeout(() => { // 0.5초간 누를경우 long press 로 인식
        if (this.hanlderStatus == 'dragstart' {
          console.log(longPress)
        }
      }, 500);

    })
    .on('drag', (pointer: any, dragX: number, dragY: number) => {
    })
    .on('dragend', (pointer: any, dragX: number, dragY: number, dropped: boolean) => {
      clearTimeout(this.longPressSettimeout);
      this.hanlderStatus = 'dragend';
    })

}

 private confirmDoubleClick() {
  if (!this.secondClick) { // this.secondClick = false;
    this.secondClick = true;
    this.time.delayedCall(300, () => { // 300 utime
      this.secondClick = false;
    });
    return false;
  }
  return true;
}

평점을 남겨주세요
평점 : 5.0
총 투표수 : 1

질문 및 답글