Krystiian Posted September 1, 2016 Share Posted September 1, 2016 (edited) So I'm having some troubles while trying to swap two Sprites; 1. When the mouse is over the sprite 2. When the mouse isn't over the sprite Everything is working fine while moving the Pointer, I'm using a group that contains many sprites sprite.inputEnabled = true; sprite.events.onInputOver.add(over, this); sprite.events.onInputOut.add(nover, this); function over(sprite){ sprite.loadTexture("spriteTargeted", 0); sprite.over = true; } function nover(sprite){ sprite.loadTexture("spriteNotTargeted", 0); sprite.over = false; } Those sprites will be falling from the top of the screen, if the pointer IS MOVED over one of those sprites, they will be swaped correctly. The problems If the pointer is PLACED ('Not Targeted' sprite will be displayed) in one pixel without being moved and one of those falling sprites collides with the mouse pointer, the 'Targeted Sprite' would not be displayed and the 'Targeted' sprite will remain displayed. If the pointer is PLACED over one sprite ('Targeted Sprite will be displayed) and the pointer remains without any other iteration, the falling sprite will leave the pointer 'boundingBox' the 'Not Targeted' sprite would not be displayed and the 'Targeted' sprite will remain displayed. If the pointer is PLACED over one sprite ('Targeted Sprite will be displayed) and the user ALT+TAB to any other window and move the pointer, when you ALT+TAB back, the 'Targeted Sprite' will remain. I Found a solution looping over all those childrens and checking if the Pointer coordinates are inside the 'boundingbox' of one of those sprites and then swapping the sprites but its quite hard-coded and many calculations are being used when the group contains too many elements. Is there any efficient method to solve this problem? Thank you Edited September 6, 2016 by Krystiian title Link to comment Share on other sites More sharing options...
symof Posted September 3, 2016 Share Posted September 3, 2016 This should be what your are looking for http://phaser.io/examples/v2/buttons/action-on-click Link to comment Share on other sites More sharing options...
Krystiian Posted September 4, 2016 Author Share Posted September 4, 2016 On 3/9/2016 at 4:34 AM, symof said: This should be what your are looking for http://phaser.io/examples/v2/buttons/action-on-click It's not, because the Sprite is static so the problem does not exist. The problem starts when the Sprite is not static like in this example: http://phaser.io/examples/v2/input/pixel-perfect-click-detection If you put your mouse in one pixel over the Rabbit, it's gonna be detected as 'over', but if you keep the pointer in the same position (without moving it) and wait a bit till the rabbit rotates enough to leave the pointer collision(theorically), the collision should not be detected anymore but it persist, so im trying to figure out one way to solve it without the need to loop every sprite every frame. Anyway, thank you for your reply. Link to comment Share on other sites More sharing options...
samme Posted September 4, 2016 Share Posted September 4, 2016 Try setting `pointer.dirty` on each update: http://codepen.io/anon/pen/rraZPX Link to comment Share on other sites More sharing options...
Krystiian Posted September 5, 2016 Author Share Posted September 5, 2016 On 4/9/2016 at 8:46 PM, samme said: Try setting `pointer.dirty` on each update: http://codepen.io/anon/pen/rraZPX Working perfectly, thank you man appreciate it. Link to comment Share on other sites More sharing options...
Recommended Posts