xzereus Posted February 27, 2014 Share Posted February 27, 2014 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 More sharing options...
XekeDeath Posted February 27, 2014 Share Posted February 27, 2014 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 More sharing options...
xzereus Posted February 27, 2014 Author Share Posted February 27, 2014 I was hoping there was something a bit easier (like events per layer), but this will work. Thanks! Link to comment Share on other sites More sharing options...
rich Posted February 28, 2014 Share Posted February 28, 2014 Tilemap has a getTileWorldXY() function which takes pixel values (i.e. could take the pointer x/y coords). grinmonk 1 Link to comment Share on other sites More sharing options...
Recommended Posts