Jump to content

Detecting click on a tile


xzereus
 Share

Recommended Posts

I'm working on a basic little JRPG just to learn more about Phaser. I've got arrow controls working, but I'm trying to experiment with point and click. I've created a function that takes in a point (x, y) and moves the character to that point.

 

All I need to do is find the TILE'S x and y coordinates when that particular tile is clicked. All of the tiles I need to handle this for are on a single layer. I've tried adding an onInputDown event to the individual tiles and the layers, but it doesn't work (tiles don't have events, layers don't have onInputDown event). What's the best way to do something like this?

 

Thanks!

Link to comment
Share on other sites

Use a generic mouse down call, and calculate the position:

clickCallback = function(pointer){    //Tiles world coordinates:    var tileworldX = pointer.worldX - (pointer.worldX%tileWidth);    var tileworldY = pointer.worldY - (pointer.worldY%tileHeight);    //click at 100, 200 world give you 64, 192    //Tiles coordinates in the grid coords (eg 4 tiles across, 7 down):    var tileX = pointer.worldX / tileWidth;    var tileY = pointer.worldY / tileHeight;    //click at 100, 200 world give you 1, 3}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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