valueerror Posted April 24, 2014 Share Posted April 24, 2014 or phrased differently.. how do i get my polygons (created on an object layer in tiled) to appear in my phaser game world ? thx! Link to comment Share on other sites More sharing options...
JP91 Posted May 5, 2014 Share Posted May 5, 2014 https://googledrive.com/host/0B2Br6oKX-RFNUTRnUjYwZ0lKSUE/mapas.htmlhey valueerror in this example all done with polygons, is that what you're trying to do? Link to comment Share on other sites More sharing options...
valueerror Posted May 6, 2014 Author Share Posted May 6, 2014 thats exactly what i was trying to do but it just doesn't work... i even copied your demo - all your assets, the code and the json file.. it works.. i also looked at the map in "tiled" it just works but when i try to load my own json file it doesn't work everything seems to be fine (no error messages) but still no collision did you do anything special in your json file ? edit: i also tried to change your poligong.json file.. i added another polygon.. the outcome - nothing changed.. your polygons collide.. my new one does not! i even browsed the code of the json file.. no visible difference.. the only thing i noticed was that your polygons aren't strictly in a 32x32 manner .. how did you do that? tiled only allows me to create polygons along the 32x32 raster.. Link to comment Share on other sites More sharing options...
JP91 Posted May 6, 2014 Share Posted May 6, 2014 Just change the name of the object layer in my json file, maybe your polygons not close completely, try to see if they are being loaded map.collision. I modified the size when I add a new tileset "tile width" and "tile height ". Link to comment Share on other sites More sharing options...
valueerror Posted May 6, 2014 Author Share Posted May 6, 2014 i don't understand.. why should i change the name of the object layer in your json file.. i tried your json file and all your polygons on the objectlayer "capa objeto" load and collide properly.. when i add another polygon (closed of course) your's still work but the new one i just added does not collide.. i just don't get what i am doing different.. even in the source of the json file i see no difference between your objects and mine... Link to comment Share on other sites More sharing options...
valueerror Posted May 6, 2014 Author Share Posted May 6, 2014 ok.. a minute ago i found out how to make a polygon collide with other objects... i played around with your json file and found out that your objects are NOT closed completely.. they do not act as one closed form like a rectangle for example.. they still are an open polyline and just look closed because the beginning and the end overlap.. so i tried "polyline" instead of "polygon" or "rectangle" aaaaand... it works.. i don't know why but using polylines does the trick... is this a BUG or are rectangles and other closed forms just not supported yet ?? ?? and still one open question remains.. your polylines are completely offgrid they are not in any way bound to the 32x32 or any other grid size.. how?? i'm using tiled version 0.9.0 and it doesn't allow this are you using a newer verison that supports polylines offgrid? Link to comment Share on other sites More sharing options...
valueerror Posted May 6, 2014 Author Share Posted May 6, 2014 thx jp91 for your help !!! couldn't have done it without your example Link to comment Share on other sites More sharing options...
JP91 Posted May 6, 2014 Share Posted May 6, 2014 upps I forgot to say I had done with polyline , I'm also using that version, the only thing I changed is the width and height of the tileset. Link to comment Share on other sites More sharing options...
valueerror Posted May 7, 2014 Author Share Posted May 7, 2014 hmmm..but when i open your tilemap it has 32*32 tiles.. thats weird..just to clear up my confusion..when you say tileset height/width you mean the w/h of the tiles on the map.. right? 'cause changing the w/h of my tileset images doesnt affect the behaviour of the grid where i paint the polylines..may i ask how small your tiles were.. the polyline connection points are all on so different heights/widths.. must be 8*8 or something.. Link to comment Share on other sites More sharing options...
JP91 Posted May 8, 2014 Share Posted May 8, 2014 Map size: w/h:16 Tile size: 32x32, the blue gem:46x36, when the polyline is drawn, you can create them the size you want. Link to comment Share on other sites More sharing options...
valueerror Posted May 8, 2014 Author Share Posted May 8, 2014 hey JP91 .. because you said that "when the polyline is drawn, you can create them the size you want." i opened up tiled again (freshly motivated) and gave it yet another try.. nothing.. i could create polylines only along the grid.. then i went through the settings and found "magnetic raster" turned on!! i turned this option of and now i can paint polylines wherever i want... yay!! so this thread is definitely solved ! thx again! Link to comment Share on other sites More sharing options...
JP91 Posted May 8, 2014 Share Posted May 8, 2014 jejeje, already strange to me that you could not do . Link to comment Share on other sites More sharing options...
wayfinder Posted June 11, 2014 Share Posted June 11, 2014 For reference, you can place points anywhere in Tiled even with the raster active, if you hold the CTRL key! ...and, with a little tinkering, you can use polygons instead of polylines as well. Here's the code. I load the JSON file as a physics object and not a tilemap (I don't actually know if this makes a difference or not):this.load.physics('level', 'assets/level.json');And then I parse the physics data manually in my create function:this.scenery = new Phaser.Group(this, this.world, null, false, true, Phaser.Physics.P2); this.levelData = this.cache.getPhysicsData('level'); for (i = 0; i < this.levelData.layers[1].objects.length; i++) { this.scenery.addAt(this.add.sprite(this.levelData.layers[1].objects[i].x, this.levelData.layers[1].objects[i].y), i); this.physics.p2.enable(this.scenery.children[i], true); this.scenery.children[i].body.clearShapes(); thepolygon = this.levelData.layers[1].objects[i].polygon; polygonarray = []; for (j = 0; j < thepolygon.length; j++) { polygonarray[j] = [thepolygon[j].x, thepolygon[j].y]; } this.scenery.children[i].body.addPolygon({}, polygonarray);}Careful about which layer you poll though Link to comment Share on other sites More sharing options...
mhobbit Posted October 13, 2014 Share Posted October 13, 2014 Hi! im sorry for reviving this thread but im encounting the same errors that valueerror had, i add polygons to the json file and they dont collide just like in my game. How i do for them to collide? Link to comment Share on other sites More sharing options...
valueerror Posted October 13, 2014 Author Share Posted October 13, 2014 you need to make sure your painting with the polyLINE tool not the polygon tool and then make sure you close the polyline object precisely ... are you using collisiongroups? if so you need to apply the group to the objects in a for loop Link to comment Share on other sites More sharing options...
Recommended Posts