Zenext Posted November 18, 2015 Share Posted November 18, 2015 Hi everyone, Is there a way to get object like getTile method for tiles? I am making grid based game and i need to check if there are any objects on specific tile position. Thanks in advance. Link to comment Share on other sites More sharing options...
forkgame Posted November 19, 2015 Share Posted November 19, 2015 I didnt quite get your question.can't you just use tileMap.getTile(x,y) ??? Link to comment Share on other sites More sharing options...
Zenext Posted November 19, 2015 Author Share Posted November 19, 2015 Yes, but it returns tile, and I need to get object from object layer. Link to comment Share on other sites More sharing options...
drhayes Posted November 19, 2015 Share Posted November 19, 2015 It depends what you mean: do you mean get the object from the JSON object Tiled made, or get the Phaser object? The JSON object is still available in the cache. You'll probably have to iterate over every object, though. Link to comment Share on other sites More sharing options...
Zenext Posted November 19, 2015 Author Share Posted November 19, 2015 I want to get Phaser object. Link to comment Share on other sites More sharing options...
jmp909 Posted November 20, 2015 Share Posted November 20, 2015 I am assuming you want to know if a Tiled 'Object Layer' object intersects with a certain grid position? Link to comment Share on other sites More sharing options...
san40511 Posted November 20, 2015 Share Posted November 20, 2015 you need add custom param for your object. And after by means methods .hasOwnProperty(your param) and method forEach get your object from object layer. this.map = this.add.tilemap('tilemap');var objects = this.map.objects;var myObj;objects.forEach(function(el){ if(el.hasOwnProperty(customParam) && el.customParam==customParamValue){ myObj=el; }}) Link to comment Share on other sites More sharing options...
forkgame Posted November 20, 2015 Share Posted November 20, 2015 the tile itself is an object, isn't it? maybe it will get your question clear.after get the object, what do you want to do with that?something you can't do with 'tile Object'? Link to comment Share on other sites More sharing options...
s4m_ur4i Posted November 21, 2015 Share Posted November 21, 2015 the code above doesn't work for me.this.map = this.add.tilemap('tilemap'); throws an error: cannot read "width" of undefined.is there a method or something to get all tiles of an existing tilemap?regards, Link to comment Share on other sites More sharing options...
jmp909 Posted November 23, 2015 Share Posted November 23, 2015 Are you using any tile layers? Link to comment Share on other sites More sharing options...
s4m_ur4i Posted November 23, 2015 Share Posted November 23, 2015 @jmp909 - no, not yet. No layers, just 128 128 generated tileMap data, I'm interested because I opened another post on tilemaps:I am able to save files natively by full OS support with node modules via nwjs, but I have not found a way to save generated tilemaps with phaser into real files- because of the object structure:http://www.html5gamedevs.com/topic/18787-save-tilemap-data-using-nwjs-phaserjs-and-node-fs-can-save-files-convert-tilemap-in-tiled-json-like-file/ Link to comment Share on other sites More sharing options...
Recommended Posts