Skip to content

Commit

Permalink
fixed p2 physics loading format and added the ability to extract a si…
Browse files Browse the repository at this point in the history
…ngle fixture
  • Loading branch information
georgiee committed Mar 31, 2014
1 parent 0a456d8 commit 0d77b36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/loader/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,15 @@ Phaser.Cache.prototype = {
},

/**
* 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.
* 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.
*
* @method Phaser.Cache#getPhysicsData
* @param {string} key - Asset key of the physics data object to retrieve from the Cache.
* @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.
* @param {string} fixtureKey - Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
* @return {object} The requested physics object data if found.
*/
getPhysicsData: function (key, object) {
getPhysicsData: function (key, object, fixtureKey) {

if (typeof object === 'undefined' || object === null)
{
Expand All @@ -594,7 +595,28 @@ Phaser.Cache.prototype = {
{
if (this._physics[key] && this._physics[key].data[object])
{
return this._physics[key].data[object];
fixtures = this._physics[key].data[object];

//try to find a fixture by it's fixture key if given
if (fixtures && fixtureKey)
{
for(var fixture in fixtures)
{
//this contains the fixture data of a polygon or a circle
fixture = fixtures[fixture]
//test the key
if(fixture.fixtureKey === fixtureKey)
{
return fixture;
}
}

//we did not find the requested fixture
console.warn('Phaser.Cache.getPhysicsData: Could not find given fixtureKey: "' + fixtureKey + ' in ' + key + '"');
}else{
return fixtures;
}

}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ Phaser.Loader.prototype = {

if (typeof dataURL === "undefined") { dataURL = null; }
if (typeof jsonData === "undefined") { jsonData = null; }
if (typeof format === "undefined") { format = Phaser.Loader.PHYSICS_LIME_CORONA_JSON; }
if (typeof format === "undefined") { format = Phaser.Physics.LIME_CORONA_JSON; }

if (dataURL == null && jsonData == null)
{
Expand Down

0 comments on commit 0d77b36

Please sign in to comment.