jakedotdk Posted December 5, 2015 Share Posted December 5, 2015 Hi I am coding a small tilebased-top-down adventuregame.I'm learning Phaser as I go along, and I've discovered the setTileIndexCallback method.map.setTileIndexCallback(tileIndex, callBackFunction, this); It's working like a charm ... except for the fact that I only want it to trigger the callback function when my character enters the tile.It seems as though every Update() triggers the callback function as long as the player and the tile overlap.Is there any way to alter this behavior so it only triggers when the character enters the tile? Kind regards - Jakob Link to comment Share on other sites More sharing options...
jakedotdk Posted December 8, 2015 Author Share Posted December 8, 2015 Fixed it myself... a ) add a global variablevar currentTile;b ) set up the tileindexcallback as usual (TileType.chest is the index of the tile type) game.map.setTileIndexCallback(TileType.chest, this.hitChest, this);c ) in the callback function check whether this tile is the last one hit, and if it is - return immediately, otherwise do stuff, and remember this tile in the global variable: hitChest: function (sprite, tile) { if (tile === currentTile) { return } else { currentTile = tile; }; //do stuff },/Jake Link to comment Share on other sites More sharing options...
ekeimaja Posted December 8, 2015 Share Posted December 8, 2015 please mark this topic to answered. Link to comment Share on other sites More sharing options...
Recommended Posts