Jump to content

Object not appearing with tilemap


ceb
 Share

Recommended Posts

I have objects in my maps with tile map and i call them like this:

 

setStuff: function()        {            firstGroup = this.add.group();            map.createFromObjects('anItem', 304/*itsJSONTileID*/, '/*Preloadedimagename*/ 'itemPic', 0, true, false, firstGroup /*added to the group*/);        },

then i kill like this:

killItem: function(player, itemPic)            {                console.log('Overlap kill');                itemPic.kill();                            },

and have overlap like so:

this.physics.overlap(player, firstGroup, this.killItem, null, this);

You need to add the object layer to the map in TILED then export then add the code accordingly. Also worth noting im in 1.1.5 phaser and see you're using 1.1.6 phaser. I'm unsure on any difference made to the object layer but have a look at the posted code and see if it helps you.

Link to comment
Share on other sites

Are you adding another layer to your tilemap in TILED, setting it as object and loading in the image?

There is quite a few steps to getting it working.

First off: make a new layer in tiled and add the image for the coin to the layer inside tiled.

Export the map and then scroll down the bottom of the new JSON file, it will hold the names you need for loading into phaser. After you have them steps complete, you need to add the group and then add to the group from the JSON. Hence the - map.createFromObjects code in the above posted code. Once they are in place you will see them ingame but have no interaction with them. You need to set the overlap with the player then the item then callback to a function. In the function kill the item, add to the score or whatever it is you want it do on overlap.

Maybe look at the simpler parts of JSON code tilemap then look at the examples AND the JSON that accompanies the example and compare from the JSON to the code so you know what you are looking to add from it.

Link to comment
Share on other sites

It is possible because I do it myself but what I don't understand is that you have 2 versions. 1 works and the other does not. So can you not use the working version instead OR look at the working versions code and use it to better code into the version required.

The information you need I have told you and there is examples and you have a working version. The only step now is to add that to your game you want it to work on.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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