tametick Posted December 10, 2013 Share Posted December 10, 2013 Hi,I'm using phaser's Tilemap to read the following map from Tiled: http://pastebin.com/p6jSrnQv (this is what it looks like: http://i.imgur.com/3bp6JFg.png) Now, although the first layer of tiles is read properly, the object layer that comes after it doesn't seem to get read at all. I have this in the preloader:game.load.tilemap('level', 'assets/level0.json', null, Tilemap.TILED_JSON); and later:var tileMap = Main.game.add.tilemap('level'); when i try to log tileMap.layers it only shows one layer (the first one). Any idea how to get the object layer? Thanks,Ido. Link to comment Share on other sites More sharing options...
rich Posted December 10, 2013 Share Posted December 10, 2013 In 1.1.3 object layers are currently skipped. In 1.1.4 they are supported, but this is still in the dev branch at the moment (final release will be end of this month). Link to comment Share on other sites More sharing options...
tametick Posted December 10, 2013 Author Share Posted December 10, 2013 Ah alright! Ignore the patch file I emailed you then Link to comment Share on other sites More sharing options...
eka Posted December 10, 2013 Share Posted December 10, 2013 Nice, I was just working on something like this. My idea is to have an Entity registry and to be able to create entities based on the object properties, so I don't have to create all the objects by hand. @rich where I can see this so I see how it's implemented and I don't do the same again? Link to comment Share on other sites More sharing options...
eka Posted December 10, 2013 Share Posted December 10, 2013 aww... my solution depends on zOrder... is there any plan to add zOrder to phaser? Link to comment Share on other sites More sharing options...
jcs Posted December 10, 2013 Share Posted December 10, 2013 my 'nadion' phaser add-on/library (https://github.com/jcd-as/nadion) uses a method like this to load objects. no registry, it simply looks for the object first in the Nadion namespace, then in the namespace the object gives (if any) and lastly in the global namespace. (nadion is some share-able bits pulled from the project I'm working on, mainly around using Tiled to design levels) looks like I may need to amend it to work with 1.1.4 Link to comment Share on other sites More sharing options...
rich Posted December 10, 2013 Share Posted December 10, 2013 aww... my solution depends on zOrder... is there any plan to add zOrder to phaser? You can z-order sprites on a Group level already. There's an example for this I'm pretty sure! I've definitely made one before anyway Link to comment Share on other sites More sharing options...
WeaveMN Posted December 12, 2013 Share Posted December 12, 2013 If you can't wait for 1.1.4 to read the object layer data I whipped up this simple function leveraging jQuery.each() and a switch statement. function addEntities(){ //get the raw map JSON so we can access the object layer mapData = game.cache.getTilemapData('game1'); monsters = game.add.group(); $.each(mapData.data.layers, function(index, layer){ if(layer.type == 'objectgroup') { $.each(layer.objects, function(index, obj){ switch(obj.name) { case 'player': sprite = game.add.sprite(obj.x, obj.y, 'guy'); sprite.anchor.setTo(0.5, 0.5); game.camera.follow(sprite); break; case 'monster': var monsterNum = Math.floor((Math.random()*2)+1); monsters.create(obj.x, obj.y, 'monster'+monsterNum) break; case 'exit': break; } }); } });}Hope that helps, WeaveMN Link to comment Share on other sites More sharing options...
Recommended Posts