owen Posted August 14, 2014 Share Posted August 14, 2014 Sorry this is very simple newbie question - I've looked for answers but can't find a simple example of this. I have a Tiled map with a Tile Layer ("Tile Layer 1") and an Object Layer ("Object Layer 1"). The Tile Layer is displaying fine but I don't know how to get anything to show up from my Object Layer. The idea is that my Object Layer is going to be purely for moving sprites while my tile layer is for static platforms, scenery etc. So far I have only attempted to add 1 sprite (a "1 ton weight") of which I've added four occurrences in the map (see screen shot). In my code I have the following for my Object Layer but I don't know how to finish the job. In preload() I have attempted to preload the sprite sheet:game.load.spritesheet('sprites32x32', 'assets/ss-sprites32x32.png', 32, 32);In create() I have attempted to initialise a group for these: tons = game.add.group(); tons.enableBody = true;But what comes next? I need to add my 4 x 'ton' sprites into the group and make them appear on screen. (I don't know the syntax, can you help?) If it helps, I have given each of them a 'spritename' property of "ton" in Tiled. I was thinking I could somehow add all the sprites where spritename=="ton" to the "tons" group. What would be the simplest way to get them to appear? (I can worry about their physics later but once displayed I'll want them to drop on to the platform underneath). Any ideas how I can get these sprites to appear? ThanksOwen Link to comment Share on other sites More sharing options...
kidos Posted August 14, 2014 Share Posted August 14, 2014 you could use createFromObjects() with your tilemap you can see an example here:http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=create+from+objects.js&t=create%20from%20objects owen 1 Link to comment Share on other sites More sharing options...
owen Posted August 15, 2014 Author Share Posted August 15, 2014 you could use createFromObjects() with your tilemap you can see an example here:http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=create+from+objects.js&t=create%20from%20objects Thanks I will use it. But I have one more problem. The example includes this line:// 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);But how do I know what the Object ID is for the object in question (in this example 34) so I can use it in my code? Is it possible to see the object ID anywhere on Tiled? Thanks,Owen Link to comment Share on other sites More sharing options...
wayfinder Posted August 15, 2014 Share Posted August 15, 2014 I never found out where that information resides in the Tiled GUI, so I had to look at the JSON :/ valueerror 1 Link to comment Share on other sites More sharing options...
owen Posted August 15, 2014 Author Share Posted August 15, 2014 Hmm I may be wrong but I think you can actually work it out by looking at your tileset if do something likevar id = tileset.firstgid + tspos...where tspos is the number of tiles along from the top-left of the tileset.? Does that sound right? I will try it later. Ideally though I would like to make use of the properties of my tileset tiles. As per my original post if have a property "spritename" with vaue "ton" then surely I could add all of the objects with spritename="ton" to the game? (Instead of relying on numeric indexes of tiles) Link to comment Share on other sites More sharing options...
kidos Posted August 15, 2014 Share Posted August 15, 2014 Hmm I may be wrong but I think you can actually work it out by looking at your tileset if do something likevar id = tileset.firstgid + tspos...where tspos is the number of tiles along from the top-left of the tileset.? Does that sound right? I will try it later. Ideally though I would like to make use of the properties of my tileset tiles. As per my original post if have a property "spritename" with vaue "ton" then surely I could add all of the objects with spritename="ton" to the game? (Instead of relying on numeric indexes of tiles) As far as I know (but maybe I'm wrong), you can't do that, but you could use foreach to check every tile if is has the property you want. Link to comment Share on other sites More sharing options...
Recommended Posts