Jump to content

p2.convertCollisionObjects not handling properties set in editor "tiled"


valueerror
 Share

Recommended Posts

according to the source:

http://docs.phaser.io/World.js.html#sunlight-1-line-1461

 

convertCollisionObjects  gets the properties

// properties: json.layers[i].objects[v].properties,

but does not do anything with it..

 

 

createBody  would accept "options" int the 5th field but is using them to create the polygon.

http://docs.phaser.io/World.js.html#sunlight-1-line-1378

var result = body.addPolygon(options, data);

so this is not the way to go..  (because addPolygon is only taking 3 special options ..

 

 

so i instead of using this (real game example:)

collisionareas =   game.physics.p2.convertCollisionObjects(map,"collisionareas");

i am now using this:

 var collisionareas = []; var layer = "collisionareas" for (var i = 0, len = map.collision[layer].length; i < len; i++)  {     var object = map.collision[layer][i];     var body = game.physics.p2.createBody(object.x, object.y, 0, true,  {} , object.polyline);     body.properties = object.properties;     if (body){ collisionareas.push(body);}  }

then i am able to access the properties set in tiled on my collisonareas (polylines)

for (i=0; i<collisionareas.length; i++){        if (collisionareas[i].properties.action == 'ramp'){           collisionareas[i].onBeginContact.add(jumpOnRamp, this);        }    }

now my question is:

 

did i NOT see the obvious way how to do this or is this just not implementet (yet)

 

and.. is this ok to do this or is it dangerous to use something like "body.properties"  because it is used somewhere else and will cause me troubles later on?

 

thx in advance!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...