Skip to content

Commit 17831e0

Browse files
committed
P2.Body.loadPolygon now allows the key parameter to be passed as null - when this happens the object parameter can be the actual physics object data instead of a string pointing to the cache, allowing you to take advantage of adding multiple convex shapes with automatic adjustments for center of mass phaserjs#1801
1 parent cf83f51 commit 17831e0

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Version 2.4 - "Katar" - in dev
309309
* Rectangle.random will return a uniformly distributed random point from anywhere within the rectangle.
310310
* Line.rotate allows you to rotate a line by the given amount around its center point.
311311
* Device.chromeVersion will return the major version number of Chrome.
312+
* TilingSprite.textureDebug is a new boolean that allows you to visually debug the generated texture a TilingSprite creates.
312313

313314
### Updates
314315

@@ -348,6 +349,7 @@ Version 2.4 - "Katar" - in dev
348349
* ScaleManager.scaleSprite will no longer try and scale a display object that doesn't have a scale property.
349350
* The LoadTexture component has a new property `customRender` which is checked for in the Core postUpdate to know when to render custom elements like Videos.
350351
* BitmapText line spacing and word wrapping has been vastly improved and bought in-line with how Pixi 3 handles it, but with additional anchor support.
352+
* P2.Body.loadPolygon now allows the `key` parameter to be passed as `null` - when this happens the `object` parameter can be the actual physics object data instead of a string pointing to the cache, allowing you to take advantage of adding multiple convex shapes with automatic adjustments for center of mass #1801
351353

352354
### Bug Fixes
353355

src/physics/p2/Body.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,15 +1253,29 @@ Phaser.Physics.P2.Body.prototype = {
12531253

12541254
/**
12551255
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
1256+
*
1257+
* As well as reading the data from the Cache you can also pass `null` as the first argument and a
1258+
* physics data object as the second. When doing this you must ensure the structure of the object is correct in advance.
1259+
*
1260+
* For more details see the format of the Lime / Corona Physics Editor export.
12561261
*
12571262
* @method Phaser.Physics.P2.Body#loadPolygon
1258-
* @param {string} key - The key of the Physics Data file as stored in Game.Cache.
1259-
* @param {string} object - The key of the object within the Physics data file that you wish to load the shape data from.
1263+
* @param {string} key - The key of the Physics Data file as stored in Game.Cache. Alternatively set to `null` and pass the
1264+
* data as the 2nd argument.
1265+
* @param {string|object} object - The key of the object within the Physics data file that you wish to load the shape data from,
1266+
* or if key is null pass the actual physics data object itself as this parameter.
12601267
* @return {boolean} True on success, else false.
12611268
*/
12621269
loadPolygon: function (key, object) {
12631270

1264-
var data = this.game.cache.getPhysicsData(key, object);
1271+
if (key === null)
1272+
{
1273+
var data = object;
1274+
}
1275+
else
1276+
{
1277+
var data = this.game.cache.getPhysicsData(key, object);
1278+
}
12651279

12661280
// We've multiple Convex shapes, they should be CCW automatically
12671281
var cm = p2.vec2.create();

0 commit comments

Comments
 (0)