Jump to content

Creating interactive tiles.


gravehopper
 Share

Recommended Posts

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

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

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

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

 Share

  • Recently Browsing   0 members

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