dst Posted March 23, 2014 Share Posted March 23, 2014 Not sure if this is a bug or not but I'm getting some weird issues when using sprite.input.pointerOver(). I have an array of sprites that I loop over in my onMouseTap function (listener is attached using game.input.onTap.add). I check for pointerOver() and move the sprite to a random position on the stage. When I then click away from the sprite pointerOver must still be returning true as the sprite moves again. Not only that but clicking multiple sprites moves all the ones already clicked.Haven't looked into Phaser's inner workings yet so I'm not sure if this is a bug or that I'm just using it incorrectly. Hopefully someone with more knowledge can advise! Demo here: https://dl.dropboxusercontent.com/u/4352121/pointerOverTest/index.htmlAnd here's the code:var game = new Phaser.Game(320, 480, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });var diamonds;function preload() { game.load.image("diamond", "diamond.png");}function create() { diamonds = []; var diamond; for (var i = 0; i < 3; i++) { diamond = game.add.sprite(0, 0, "diamond"); diamond.anchor.setTo(.5, .5); diamond.x = Math.floor(Math.random() * 320 + 1); diamond.y = Math.floor(Math.random() * 480 + 1); diamond.inputEnabled = true; diamonds[i] = diamond; } game.input.onTap.add(onMouseTap, this);}function update() {}function render() {}function onMouseTap() { for (var i = 0; i < diamonds.length; i++) { var diamond = diamonds[i]; if (diamond.input.pointerOver()) { diamond.x = Math.floor(Math.random() * 320 + 1); diamond.y = Math.floor(Math.random() * 480 + 1); } }} Link to comment Share on other sites More sharing options...
valueerror Posted March 23, 2014 Share Posted March 23, 2014 maybe related to my post.. (read bug nr# 2) http://www.html5gamedevs.com/topic/4406-2-possibe-bugs-with-phaserbutton/ update to 2.0.1 and see if it still happens ! Link to comment Share on other sites More sharing options...
dst Posted March 23, 2014 Author Share Posted March 23, 2014 maybe related to my post.. (read bug nr# 2) http://www.html5gamedevs.com/topic/4406-2-possibe-bugs-with-phaserbutton/ update to 2.0.1 and see if it still happens ! Hi valueerror, I just upgraded but the problem is still there Is there something I'm not doing correctly? https://dl.dropboxusercontent.com/u/4352121/pointerOverTest/index.html Link to comment Share on other sites More sharing options...
rich Posted March 24, 2014 Share Posted March 24, 2014 pointerOver is really an internal method (and probably ought to be documented as such actually) used as part of the hit test sequence. Here is how I would re-write your code above (note I swapped to use a tween just so you can visually see the repositioning happen)var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });function preload() { game.load.image("diamond", "assets/sprites/diamond.png");}function create() { var diamond; for (var i = 0; i < 16; i++) { diamond = game.add.sprite(game.world.randomX, game.world.randomY, "diamond"); diamond.anchor.set(0.5); diamond.inputEnabled = true; diamond.events.onInputDown.add(clickedDiamond, this); }}function clickedDiamond(diamond) { game.add.tween(diamond).to({ x: game.world.randomX, y: game.world.randomY }, 250, Phaser.Easing.Linear.None, true);} Link to comment Share on other sites More sharing options...
dst Posted March 24, 2014 Author Share Posted March 24, 2014 Thanks Rich. Your solution is the same as my initial attempt but I couldn't find a way to get a reference to the clicked object in the callback (hence why I was using pointerOver). I see that the callback is now passed a reference to the object, is that something new in 2.0? Link to comment Share on other sites More sharing options...
rich Posted March 24, 2014 Share Posted March 24, 2014 No it's always done it It passes the item itself first (the sprite) and then the pointer that caused the click 2nd. Link to comment Share on other sites More sharing options...
dst Posted March 25, 2014 Author Share Posted March 25, 2014 Doh, my bad. Thanks for the advice Link to comment Share on other sites More sharing options...
jdnichollsc Posted February 8, 2015 Share Posted February 8, 2015 How Can I Know if above the sprite into the game.input.onDown method? Because .input.pointerOver() also shows me error in Phaser v2.2.2 with CocoonJS Regards, Nicholls Link to comment Share on other sites More sharing options...
jdnichollsc Posted February 9, 2015 Share Posted February 9, 2015 Ohh this works! this.sound.input.pointerDown(this.game.input.activePointer.id) Regards, Nicholls Link to comment Share on other sites More sharing options...
Recommended Posts