Jump to content

How to specify which tile in a tilemap which is draggable?


xtreme
 Share

Recommended Posts

Began with the following to make my sprite draggable. Decided to use tilemap instead.

 

This is my code

 

gamemap.json

{ "height":40,    "layers":[        {            "data":[30, 30, 10, 30],            "height":40,            "name":"Ground",            "opacity":1,            "type":"tilelayer",            "visible":true,            "width":40,            "x":0,            "y":0        }],

game.js

	create: function () {        this.add.sprite(0, 0, 'preloaderBackground')        map = this.add.tilemap('map');        map.addTilesetImage('Desert', 'tiles');        layer = map.createLayer('Ground');        layer.inputEnabled = true;        layer.input.enableDrag();

This makes all tiles becomes draggable at the same time. How do I specify which tiles that will be draggable and that only one moves at a time (the one I drag)?

Link to comment
Share on other sites

For the tiles to be individually dragable they can't be part of a real tilemap-layer.

Because on layer is something like one sprite (that is only updated if tiles change).

 

But you can still use a tilemap to define your dragable tiles, if you use this method:

 

Phaser example: objects from tilemap layers

 

This is the most relevant part:

// Here we create our coins groupcoins = game.add.group();coins.enableBody = true;// And now we convert all of the Tiled objects with an ID of 34 into sprites within the coins groupmap.createFromObjects('Object Layer 1', 34, 'coin', 0, true, false, coins);

It converts tiles to sprites. On those sprites you can then enable input.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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