horkoda Posted July 25, 2014 Share Posted July 25, 2014 Hello, I am new to Phaser and I am using 2.0.6! I have a classic orthogonal square tilemap grid of fixed size and no camera. How could I detect which tile is under the pointer when clicked/tapped? Currently, I'm thinking of detecting clicks inside the update() method. Using a combination of game.input.isDown, .x, .y and map.getTileXY(). Would that be the preferred way, or can I register an onInputDown event on the whole tilemap somehow? Thanks! EDIT: I just saw the setTileIndexCallback() method in Tilemap. I guess I should just use that, then? Link to comment Share on other sites More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 I think this is just for collisions, for input I think probably a combination of getting the pointer position when down and finding the appropriate tile via tilemap.getWorldXY. There's an example that shows how input can interact with a tilemap, however I think the way it does it is slightly outdated - it still works but it looks like getWorldXY was implemented to make this process easier: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=paint+tiles.js&t=paint%20tiles Arcanorum 1 Link to comment Share on other sites More sharing options...
horkoda Posted July 25, 2014 Author Share Posted July 25, 2014 Is there a "phaser" way to detect a click/tap event on the tilemap? Or even the whole stage?I dislike the fact that the game is detecting when the pointer is down every cycle, instead of detecting just a single click. Link to comment Share on other sites More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 Yeah, for the whole stage like so:game.input.onDown.add(function(pointer, event) { // this is run once per input down event; pointer passes the Pointer that triggered it, and event passes the DOM event}, this); Pooya72 and horkoda 2 Link to comment Share on other sites More sharing options...
horkoda Posted July 25, 2014 Author Share Posted July 25, 2014 Hehe, I've just found that function in the docs Thanks for your help, it's appreciated lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts