gravehopper Posted May 5, 2015 Share Posted May 5, 2015 Hello, I am stating out using phaser and well overall developing games in html5 but I have some experience with programming.I have a bit of a project that I have set out to do that is mainly based on creating a grid of interactive tiles.I looked through the api but could not find the exact methods used to interact and change phaser tiles. Something along the lines of make a grid of tiles 3x3 and on touch tap a tile will change to a different image with different properties.Also is there a way to make for example a player "die" if they step onto a tile with one image yet live if the same tile was "changed" via a tap. I have taken a look at the examples but I cannot seem to quite catch how the tiles are changed.\ Thanks in advance. Link to comment Share on other sites More sharing options...
jonoco Posted May 6, 2015 Share Posted May 6, 2015 I don't think tiles are meant to be directly interactive by the user. Wouldn't it be simpler to create a grid of sprite "tiles" instead? This would allow you to easily interact with the tiles by clicking them, and also check for collisions between the tiles and player. Link to comment Share on other sites More sharing options...
gravehopper Posted May 6, 2015 Author Share Posted May 6, 2015 Yeah I figured that. Right now I am in a state of searching for a method which will let me detect if the user tapped on the tile. [tile] [tile] [tile][tile] [tile] [tile][tile] [tile] [tile] Is there a way to for example destroy the tile that the user tapped on? Link to comment Share on other sites More sharing options...
drhayes Posted May 7, 2015 Share Posted May 7, 2015 If the tiles are now actual Sprites you can set inputEnabled to true on them so that they receive pointer events (e.g. taps). You then subscribe to them (they're Phaser.Signals) on the events property like this:sprite.events.onInputDown.add(myCallback);That callback could then destroy the sprite. It'll get passed as the argument to the callback... I think. You might want to "console.log(arguments);" in your callback to check. Link to comment Share on other sites More sharing options...
gravehopper Posted May 7, 2015 Author Share Posted May 7, 2015 Last question. Is there a way to obtain that exact sprite out of a group of sprites? Link to comment Share on other sites More sharing options...
drhayes Posted May 7, 2015 Share Posted May 7, 2015 That got touched? That callback could then destroy the sprite. It'll get passed as the argument to the callback... I think. You might want to "console.log(arguments);" in your callback to check. ( = Link to comment Share on other sites More sharing options...
loafer Posted May 11, 2015 Share Posted May 11, 2015 I recently needed interactive tiles as well. I added a new event listener to input.onDown and calculated the tile coordinates by dividing the worldX and worldY values of the pointer by the tile width. Then I could get the tile-object by using map.getTile(x, y, layer). But be aware that this method will trigger even when there are sprites being clicked in front of the tiles. I hope it helps anyway. Link to comment Share on other sites More sharing options...
Recommended Posts