sChupin Posted May 16, 2017 Share Posted May 16, 2017 Hi everyone, I'm trying to make a sprite moving when the mouse is over it and I'd like it to stop when the mouse is not over it anymore. Here is my code: mySprite.events.onInputOver.add(() => touchMouse = true); mySprite.events.onInputOut.add(() => touchMouse = false); and update() { if (touchMouse) { mySprite.x += 5; } } My sprite is correctly moving but the onInputOut signal is not dispatched if I don't move the pointer out of the initial position of the sprite !! This result in my sprite moving out of my pointer and continuing its journey until I move my mouse... Is it a phaser bug? Has anyone a solution to make this work? Thank you very much and have a good day, Simon Edit: I just tried to use the Phaser.InputHandler object instead but I got the same kind of bug. Here is the code: update() { if (mySprite.input.pointerOver()) { mySprite.x += 5; } } Link to comment Share on other sites More sharing options...
samme Posted May 16, 2017 Share Posted May 16, 2017 Phaser doesn't ordinarily update inputOver/inputOut events while the pointer isn't moving. You need to set pointer.dirty = true for that. Link to comment Share on other sites More sharing options...
sChupin Posted May 17, 2017 Author Share Posted May 17, 2017 Thank you very much for your answer ! I'm just not sure where to set the dirty variable to true. I tried to set it on inputOver but then it's immediately back to false and the bug still occurs. I fixed the bug by setting pointer.dirty = true in the update loop, but then it will be always reset to true. Is it the correct way to do? Link to comment Share on other sites More sharing options...
Recommended Posts