OpherV Posted June 6, 2014 Share Posted June 6, 2014 Update: Here's an example of the issue ----- In my game I have several defined "areas", that are basically dynamically generated polygons. This is an example of a set of polygon coordinates:this.pointArray=[[0,0],[300,-40],[400,-100],[500,0],[370,300],[100,450],[-100,200]];I draw these using a Graphics object and that works great: Now the weirdness begins.I try to add a body with the same polygon sensor shape using addPolygon and the same coordinates, like so: Phaser.Sprite.call(this, this.game, 0, 0); this.game.physics.p2.enable(this,true,false); this.body.clearShapes(); this.body.addPolygon({},this.pointArray); this.body.data.shapes[0].sensor=true;Below is what I get. Body shape polygon is OK, but notice that the graphics coordinates (green polygon) were shrunk down by a factor of 20, even though the only thing that was changed was the addition of the body.This affects every child object of my area sprite, so if a child object has some X value, that value will get translated to X/20! This does not happen if I use addRectangle: Phaser.Sprite.call(this, this.game, 0, 0); this.game.physics.p2.enable(this,true,false); this.body.clearShapes(); this.body.addRectangle(500,500,150,150); this.body.data.shapes[0].sensor=true;Notice how now both the rectangle body shape as well as the original coordinates behave accordingly. Now for more weirdness - If I put the addPolygon part AFTER the creation of the Graphics object I get the image below - both the polygons have the proper dimensions, but now every child sprite is offset by some amount. I'm really at a loss at how to debug this. I'm sure this has something to do with the phaser\p2 MPX conversions, but hours later into debugging and I still can't wrap my head around this.It's a crucial aspect of my game. Help! Link to comment Share on other sites More sharing options...
wayfinder Posted June 6, 2014 Share Posted June 6, 2014 Yeah, there's a *-0.05 in there somewhere, there's your 1/20th Link to comment Share on other sites More sharing options...
OpherV Posted June 6, 2014 Author Share Posted June 6, 2014 I know that there's a difference between P2 and Phaser units, but that still doesn't explain why it works properly with addRectangle (or any other shape for that matter) and not with addPolygon. Link to comment Share on other sites More sharing options...
wayfinder Posted June 6, 2014 Share Posted June 6, 2014 I just wrote code to add polygons with a point array and they seem to work fine here... Here's my code:myPolygon = this.add.sprite(x, y);this.physics.p2.enable(myPolygon, false);myPolygon.body.clearShapes();myPolygon.body.addPolygon({}, myPolygonArray);myPolygon.body.static = true;The polygon starts and ends at (0, 0) – but so does yours. Hm. Link to comment Share on other sites More sharing options...
OpherV Posted June 6, 2014 Author Share Posted June 6, 2014 @wayfinder Here's an example of the issue - as you can see it's easily recreated Link to comment Share on other sites More sharing options...
wayfinder Posted June 6, 2014 Share Posted June 6, 2014 Ahh.. Maybe you need to draw the shape before you add the polygon – in case the array itself is changed during the add edit: wait that's what you did earlier.. but I seem to remember that adding a p2 body automatically sets the anchor. Maybe if you re-set that again? edit 2: hmm no that doesn't seem to be the solution either. Could it be that the points in the array are somehow rearranged when adding the polygon? I know they are converted to counterclockwise in the process... Link to comment Share on other sites More sharing options...
george Posted June 11, 2014 Share Posted June 11, 2014 I never use that method. I have not looked at this in detail but it looks like a bug. Would you mind to create a ticket in github for this ?To get this fixed, you could try an alternative method. addPhaserPolygon. It's still undocumented. Search for it. I added that method together with the Phaser PhysicsEditor Exporter to manage all my shapes including sensors in a single PhysicsEditor File. The fileformat differs only slightly so you can the files yourself http://www.html5gamedevs.com/index.php?app=core&module=search§ion=search&do=search&fromsearch=1 RegardsGeorge Link to comment Share on other sites More sharing options...
Recommended Posts