1 decade ago by MDChristie
I have the touch buttons plugin working fine for the first menu, but later into the game when I have a pause menu the events from the first menu still exists, and seem to take precedence over the new pause menu when the buttons are in the same location.
I tried adding a kill function by copying the init function and replacing addEventListener with removeEventListener, but had no success. Is there a way to close a button collection correctly so all the event listeners are removed?
I tried adding a kill function by copying the init function and replacing addEventListener with removeEventListener, but had no success. Is there a way to close a button collection correctly so all the event listeners are removed?
init: function( buttons ) { this.buttons = buttons; document.addEventListener('touchstart', this.touchStart.bind(this), false); document.addEventListener('touchend', this.touchEnd.bind(this), false); // My added click events document.addEventListener('mousedown', this.touchStartMS.bind(this), false); document.addEventListener('mouseup', this.touchEndMS.bind(this), false); document.addEventListener('MSPointerDown', this.touchStartMS.bind(this), false); document.addEventListener('MSPointerUp', this.touchEndMS.bind(this), false); document.body.style.msTouchAction = 'none'; }