davidwesst Posted February 15, 2017 Share Posted February 15, 2017 (edited) Hello everyone, I'm working on a small game using TypeScript, and I hit a compilation issue with the Phaser.Tilemap object. I was going to submit it as an issue to GitHub, but because I'm new here I wanted to error on the side of caution and make sure that this is actually an issue, as per the contribution guidelines. According to the phaser.d.ts file, on [line 5057](https://github.com/photonstorm/phaser-ce/blob/master/typescript/phaser.d.ts#L5057), the objects project is supposed to be an any[]. When running my application, I can see that Phaser.Tilemap.objects is an Object, with another property called objects, which is an any[]. I have attached a screenshot of my code editor watch expressions that shows the issue I'm facing. If we make the following change to the def file, it would resolve the issue. I have confirmed the change in my local repository, and everything appears to compile as expected. objects: { objects: any[]; }; To generate the error, I am loading TILED_JSON map data and iterating through it to find a specific tile, as follows: let map: Phaser.Tilemap for(let o of map.objects.objects) { if(o.type === "start") { start = new Phaser.Point(o.x, o.y - map.tileHeight); break; } } Edited February 15, 2017 by davidwesst Added reason for posting here, and fixed a sentence that wasn't clear. Link to comment Share on other sites More sharing options...
drhayes Posted February 15, 2017 Share Posted February 15, 2017 Caveat: I don't do TypeScript. That doesn't look right to me, any[]... it's not an array, it's an object: https://github.com/photonstorm/phaser-ce/blob/0c9bef16b98095be79e866fbee778a78e24486c3/src/tilemap/TilemapParser.js#L172 Do you have an object layer in your map called "objects"? What happens if you change its name to "cats"? (change your code, too) hexus and davidwesst 2 Link to comment Share on other sites More sharing options...
davidwesst Posted February 15, 2017 Author Share Posted February 15, 2017 You were right! It appears that Phaser.TypeScript.objects contains my object layer and names it accordingly. I changed my code to use map.objects['objects'] (or map.objects['cats']) and everything is working as expected. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts