I'm trying to check if there's a better of way of doing this, because while it works it feels a bit sloppy, if i either click/press too much or too little. And also need to have the double click/press have priority over the single click/press without it going off.
JavaScript:
const ty_spriteClickable = Sprite_Clickable.prototype.initialize;
Sprite_Clickable.prototype.initialize = function() {
ty_spriteClickable.call(this);
this._pressCount = 0;
this._lastPressed = 0;
};
const ty_processTouch = Sprite_Clickable.prototype.processTouch;
Sprite_Clickable.prototype.processTouch = function() {
if (this.isBeingTouched() && TouchInput.isTriggered()) {
const currentInput = TouchInput.date;
const interval = Math.abs(this._lastPressed - currentInput);
if (interval < 600 && this._pressCount < 2) {
this._pressCount++;
} else if (interval > 600) {
this._pressCount = 0;
}
if (this._pressCount == 2) {
this.onDoublePress();
}
console.log(interval + ' TouchInput.date');
}
ty_processTouch.call(this);
this._lastPressed = TouchInput.date;
};
Sprite_Clickable.prototype.onDoublePress = function() {
console.log('Has been double pressed');
};