Skip to content

Commit 0d77b36

Browse files
committed
fixed p2 physics loading format and added the ability to extract a single fixture
1 parent 0a456d8 commit 0d77b36

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/loader/Cache.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,15 @@ Phaser.Cache.prototype = {
569569
},
570570

571571
/**
572-
* Get a physics data object from the cache by its key. You can get either the entire data set or just a single object from it.
572+
* Get a physics data object from the cache by its key. You can get either the entire data set, a single object or a single fixture of an object from it.
573573
*
574574
* @method Phaser.Cache#getPhysicsData
575575
* @param {string} key - Asset key of the physics data object to retrieve from the Cache.
576576
* @param {string} [object=null] - If specified it will return just the physics object that is part of the given key, if null it will return them all.
577+
* @param {string} fixtureKey - Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
577578
* @return {object} The requested physics object data if found.
578579
*/
579-
getPhysicsData: function (key, object) {
580+
getPhysicsData: function (key, object, fixtureKey) {
580581

581582
if (typeof object === 'undefined' || object === null)
582583
{
@@ -594,7 +595,28 @@ Phaser.Cache.prototype = {
594595
{
595596
if (this._physics[key] && this._physics[key].data[object])
596597
{
597-
return this._physics[key].data[object];
598+
fixtures = this._physics[key].data[object];
599+
600+
//try to find a fixture by it's fixture key if given
601+
if (fixtures && fixtureKey)
602+
{
603+
for(var fixture in fixtures)
604+
{
605+
//this contains the fixture data of a polygon or a circle
606+
fixture = fixtures[fixture]
607+
//test the key
608+
if(fixture.fixtureKey === fixtureKey)
609+
{
610+
return fixture;
611+
}
612+
}
613+
614+
//we did not find the requested fixture
615+
console.warn('Phaser.Cache.getPhysicsData: Could not find given fixtureKey: "' + fixtureKey + ' in ' + key + '"');
616+
}else{
617+
return fixtures;
618+
}
619+
598620
}
599621
else
600622
{

src/loader/Loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ Phaser.Loader.prototype = {
582582

583583
if (typeof dataURL === "undefined") { dataURL = null; }
584584
if (typeof jsonData === "undefined") { jsonData = null; }
585-
if (typeof format === "undefined") { format = Phaser.Loader.PHYSICS_LIME_CORONA_JSON; }
585+
if (typeof format === "undefined") { format = Phaser.Physics.LIME_CORONA_JSON; }
586586

587587
if (dataURL == null && jsonData == null)
588588
{

0 commit comments

Comments
 (0)