vilcans Posted April 22, 2014 Share Posted April 22, 2014 I got a problem that the P2 collision mesh is not properly aligned with the bitmap. Here's the sprite's bitmap: I measured the pixel coordinates on the bitmap and got this mesh: { "ship": [ { "density": 2, "friction": 0, "bounce": 0, "shape": [ 16, 31, 0, 29, 16, 0, 31, 29 ] } ] }And the CoffeeScript code: @ship = game.add.sprite(200, 200, 'ship') game.physics.p2.enable(@ship, true) @ship.body.clearShapes() @ship.body.loadPolygon('physicsData', 'ship')But as you can see in the image, the physics debug polygon (purple) is not properly aligned with the bitmap. My theory is that the bitmap is automatically centered on the physics polygon, because no matter how I tweak the values in the physics mesh, it won't align with the bitmap. For example, if I add 50 to all x coordinates in the polygon, the sprite will appear 50 pixels to the right, but the polygon will still be drawn on top of the sprite, not beside it. Is there a way to disable this? Link to comment Share on other sites More sharing options...
george Posted April 22, 2014 Share Posted April 22, 2014 I can confirm this. Something is going wrong with the center of mass.By using an alternative polygon data format it's working. Try this://data format from custom physics editor exporter 'phaser'.//See phaser/resources/PhysicsEditor Exporter "ship":[ { "isSensor": false, "filter": { "group": 0, "categoryBits": 1, "maskBits": 65535 }, "polygons":[ [16, 31,0, 29,16, 0,31, 29] ] } ],//ship.body.loadPolygon('physicsData', 'ship');//use this method for the alternative data format. The format is a little bit more sophisticated.ship.body.addPhaserPolygon('physicsData', 'ship');Result:The right one is created using the alternative method. It has the same y position as the ship on the left, so it's clearly something with the mass. Both ships are centered (as every p2 body). I will have a look at the default parser. Link to comment Share on other sites More sharing options...
vilcans Posted April 22, 2014 Author Share Posted April 22, 2014 OMG, it works! Thanks george! Link to comment Share on other sites More sharing options...
george Posted April 22, 2014 Share Posted April 22, 2014 You're welcome! By the way, the bug is already fixed, merged and will be available in 2.0.4. You could pull the latest version from github and go one with 'loadPolygon' as if nothing happened https://github.com/photonstorm/phaser/pull/749#issuecomment-41099916 Link to comment Share on other sites More sharing options...
vilcans Posted April 22, 2014 Author Share Posted April 22, 2014 I'm impressed by the lightspeed fix! Link to comment Share on other sites More sharing options...
neoRiley Posted April 23, 2014 Share Posted April 23, 2014 Do you guys know when 2.0.4 will be released then? Link to comment Share on other sites More sharing options...
george Posted April 23, 2014 Share Posted April 23, 2014 2.0.4 should be released by the end of the week. I guess Friday as Rich released 2.0.3 two weeks ago. Link to comment Share on other sites More sharing options...
Recommended Posts