misc/pointergesture
포인터 제스처 인식기. (헤드리스)
Pointer gesture recognizer. (headless)
PointerGestureextends Object
포인터 제스처 인식기. (헤드리스)
- 탭 / 드래그 / 롱프레스를 임계값으로 분류한다. 노드에 얽매이지 않아 어디서나 쓴다.
- 사용: press(x, y) → movePointer(x, y) → tick(dt) → release() 순으로 넘기고, 콜백(setTapEvent / setDragEvent / setLongPressEvent)으로 결과를 받는다.
- 여러 게임이 pressedTime / dragMoved 변수를 제각각 들고 다니던 것을 표준화했다.
Pointer gesture recognizer. (headless)
- Classifies tap / drag / long press by thresholds. Not tied to nodes, so it can be used anywhere.
- Usage: pass press(x, y) → movePointer(x, y) → tick(dt) → release() in order, and receive the results through callbacks (setTapEvent / setDragEvent / setLongPressEvent).
- Standardizes the pressedTime / dragMoved variables that several games each carried around.
import { PointerGesture } from "./build/vanilla.js";
const pointerGesture = new PointerGesture({ dragThreshold: 12, longPressSeconds: 0.6 });
pointerGesture.setTapEvent((position) => {
console.log("tap", position.x, position.y);
});
pointerGesture.setDragEvent((currentPosition, pressPosition) => {
console.log("drag", currentPosition.x - pressPosition.x);
});
pointerGesture.setDragEndEvent((currentPosition, pressPosition) => {
console.log("drag end", currentPosition.x - pressPosition.x);
});
pointerGesture.setLongPressEvent((pressPosition) => {
console.log("long press", pressPosition.x, pressPosition.y);
});
pointerGesture.press(100, 100);
pointerGesture.release();
pointerGesture.press(100, 100);
pointerGesture.movePointer(105, 100);
pointerGesture.movePointer(130, 100);
pointerGesture.release();
pointerGesture.press(50, 50);
pointerGesture.tick(0.3);
console.log(pointerGesture.getLongPressRatio());
pointerGesture.tick(0.3);
pointerGesture.release();생성.
Constructor.
- optionsobject
- { dragThreshold = 12, longPressSeconds = 0.6 }
짝Counterpart: vanilla-engine PointerGesture.new
누름.
Press.
- xnumber
- 포인터 X 좌표.Pointer X coordinate.
- ynumber
- 포인터 Y 좌표.Pointer Y coordinate.
짝Counterpart: vanilla-engine PointerGesture.press
이동.
- 누른 지점에서 임계값을 넘으면 드래그로 확정하고 이후 매 이동마다 dragEvent 를 부른다.
Move.
- Once it exceeds the threshold from the press point, it is confirmed as a drag and dragEvent is called on every move after that.
- xnumber
- 포인터 X 좌표.Pointer X coordinate.
- ynumber
- 포인터 Y 좌표.Pointer Y coordinate.
짝Counterpart: vanilla-engine PointerGesture.move_pointer
갱신. (롱프레스 시간 누적)
- 드래그로 확정되지 않은 채 longPressSeconds 를 넘기면 롱프레스를 한 번 알린다.
Updates. (accumulates long press time)
- If longPressSeconds passes without being confirmed as a drag, notifies a long press once.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine PointerGesture.tick
뗌.
- 드래그도 롱프레스도 아니었으면 탭으로 알린다.
Release.
- If it was neither a drag nor a long press, notifies a tap.
짝Counterpart: vanilla-engine PointerGesture.release
취소. (아무것도 알리지 않고 상태만 되돌린다)
Cancels. (notifies nothing and only resets the state)
짝Counterpart: vanilla-engine PointerGesture.cancel
롱프레스 진행 비율 반환. (게이지 표시용, 0~1)
Returns the long press progress ratio. (for gauge display, 0~1)
반환Returnsnumber 롱프레스 진행 비율. (0 ~ 1, 누르지 않았거나 드래그 중이면 0)Long press progress ratio. (0 ~ 1, 0 if not pressed or while dragging)
짝Counterpart: vanilla-engine PointerGesture.get_long_press_ratio
상태 조회.
State query.
반환Returnsboolean 누르고 있으면 참.True while pressed.
짝Counterpart: vanilla-engine PointerGesture.is_pressed
드래그 중인지 여부.
Whether dragging.
반환Returnsboolean 드래그로 확정되었으면 참.True if confirmed as a drag.
짝Counterpart: vanilla-engine PointerGesture.is_dragging
콜백 설정.
Sets the callback.
- tapEventFunction
- (position) => void
짝Counterpart: vanilla-engine PointerGesture.set_tap_event
드래그 알림 설정. (드래그로 확정된 뒤 이동마다)
Sets the drag callback. (on every move after it is confirmed as a drag)
- dragEventFunction
- (currentPosition, pressPosition) => void
짝Counterpart: vanilla-engine PointerGesture.set_drag_event
드래그 끝 알림 설정. (드래그 중에 뗄 때)
Sets the drag end callback. (when released while dragging)
- dragEndEventFunction
- (currentPosition, pressPosition) => void
짝Counterpart: vanilla-engine PointerGesture.set_drag_end_event
롱프레스 알림 설정. (드래그 없이 longPressSeconds 를 넘길 때 한 번)
Sets the long press callback. (once, when longPressSeconds passes without dragging)
- longPressEventFunction
- (pressPosition) => void
짝Counterpart: vanilla-engine PointerGesture.set_long_press_event
임계값 설정.
Sets the thresholds.
- dragThresholdnumber
- 드래그로 볼 최소 이동 거리. (press 와 같은 좌표 단위, 기본 12)Minimum movement distance treated as a drag. (same coordinate units as press, default 12)
짝Counterpart: vanilla-engine PointerGesture.set_drag_threshold
길게 누름 판정 시간 설정. (초)
Sets the long press threshold time. (seconds)
- longPressSecondsnumber
- 롱프레스로 볼 누름 시간. (초, 기본 0.6)Press time treated as a long press. (seconds, default 0.6)
짝Counterpart: vanilla-engine PointerGesture.set_long_press_seconds