Jump to content

Tile or Tilemap mouse events?


horkoda
 Share

Recommended Posts

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

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

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...