Vitali Posted September 9, 2018 Share Posted September 9, 2018 Hi, everyone! I'm developing the game with Phaser3 which needs in detecting the moment when the pointer cross over or out of particular GameObject. But I haven't found any support of "gameobjectover" and "gameobjectout" for mobile touch events. I suppose that's because the "out" and "over" events don't fit to the touch, only for the mouse. As a workaround, I've written something like that: //Scene plugin public boot():void { let prevObject:GameObject = null; this.scene.events.on("update", ()=> { let activePointer:Pointer = this.scene.input.activePointer; if (activePointer != this.scene.input.mousePointer && !activePointer.isDown) { if (activePointer.justUp) { this.scene.input.emit("gameobjecttouchout", activePointer, prevObject); prevObject = null; } return; } let hitObjects = this.scene.input.hitTestPointer(activePointer); let curObject:GameObject = (hitObjects.length > 0) ? hitObjects[hitObjects.length - 1] : null; if (prevObject != curObject) { if (!prevObject) { this.scene.input.emit("gameobjecttouchover", activePointer, curObject); prevObject = curObject; } else { this.scene.input.emit("gameobjecttouchout", activePointer, prevObject); prevObject = null; if (curObject) { this.scene.input.emit("gameobjecttouchover", activePointer, curObject); prevObject = curObject; } } } }, this); } That plugin allows me to have the "gameobjectTOUCHover" and "gameobjectTOUCHout" events. But maybe there are some other proper ways to reach this requirement. Who has faced such requirement? I will be grateful if somebody gives me the clue to improve my approach in detecting this events. P.S.: Sorry for my dirty code and English. Link to comment Share on other sites More sharing options...
iKest Posted September 10, 2018 Share Posted September 10, 2018 Глобальный инпут передает в калбэк поинтер и пул объектов имеющих активную область, которые находятся под поинтером в момент события: input.on('pointerout', ( pointer, obj) => {...} , scope) input.on('pointerover', ( pointer, obj) => {...}, scope) т.е. мы можем присвоить объекту имя someObject.name = 'name' и потом проверять его в калбэке примерно так: input.on('pointerover', ( pointer, obj) => { if (obj.some((arg) =>arg.name == 'name')) { } else { } } , scope) или можно навешивать слушатели на каждый конкретный объект: someObject.on('pointerout', ( pointer) => {...} , scope) someObject.on('pointerover', ( pointer) => {...}, scope) https://rexrainbow.github.io/phaser3-rex-notes/docs/site/touchevents/ ЗЫ. Извините за мой плохой код и Русский. Link to comment Share on other sites More sharing options...
Vitali Posted September 13, 2018 Author Share Posted September 13, 2018 I'm not sure that I've got it correctly. But your approach works only when the current pointer is mousePointer. Link to comment Share on other sites More sharing options...
iKest Posted September 13, 2018 Share Posted September 13, 2018 no. its 4both inputs:mouse and touch. i'use it in my game. Link to comment Share on other sites More sharing options...
Vitali Posted September 13, 2018 Author Share Posted September 13, 2018 Have you checked exactly 'pointerover' and 'pointerout'? Because I know - 'pointerdown' and 'pointerup' work fine for both inputs. Link to comment Share on other sites More sharing options...
Archydemon Posted March 28, 2019 Share Posted March 28, 2019 Bumped into this post with the same problem. I was not able to make "pointerover" event work on mobile. Got any updates on this? Link to comment Share on other sites More sharing options...
Recommended Posts