I have this code working fine earlier but instantly it started giving an error
e.touches.map is not a function!
Error place ButtonLogic.prototype.onTouchEnd
var ButtonLogic = pc.createScript('buttonLogic');
//initialize code called once per entity
ButtonLogic.prototype.initialize = function() {
this.button = this.entity.button;
this.button.on('mouseenter', this.onMouseEnter, this);
this.button.on('mouseleave', this.onMouseLeave, this);
this.button.on('touchstart', this.onTouchStart, this);
this.button.on('touchend', this.onTouchEnd, this);
this.button.on("destroy", ()=>{
this.button.off('mouseenter', this.onMouseEnter, this);
this.button.off('mouseleave', this.onMouseLeave, this);
this.button.off('touchstart', this.onTouchStart, this);
this.button.off('touchend', this.onTouchEnd, this);
}, this);
};
// Having it this simplistic may cause problems if we ever have buttons overlapping each other
ButtonLogic.prototype.onMouseEnter = function(e) {
Selector.instance.mouseOverButton = true;
};
ButtonLogic.prototype.onMouseLeave = function(e) {
Selector.instance.mouseOverButton = false;
};
ButtonLogic.prototype.onTouchStart = function(e) {
for (let touch of e.changedTouches) {
Selector.instance.fire("addTouchID", touch.id);
}
};
ButtonLogic.prototype.onTouchEnd = function(e) {
// Complex version (no leftovers)
let eventTouchIDs = e.touches.map(touch => touch.id);
for (let touchID of Selector.instance.touchIDsOverButtons) {
if (!eventTouchIDs.includes(touchID)) Selector.instance.fire("removeTouchID", touchID);
}
};