Getting collision id on specific shape from PhysicsEditor?

Hi all,
I’m wondering if anybody has any experience using PhysicsEditor with Corona and getting specific shape id’s upon collision?

This is what I’m getting from PhysicsEditor:

function physicsData(scale)  
 local physics = { data =  
 {   
  
 ["backboard"] = {  
  
 {  
 pe\_fixture\_id = "backboard", density = 2, friction = 0, bounce = 0,   
 filter = { categoryBits = 1, maskBits = 65535 },  
 shape = { -7, -132.5 , -59, -72.5 , -59, -214.5 , -7, -214.5 }  
 } ,  
 {  
 pe\_fixture\_id = "pole", density = 2, friction = 0, bounce = 0,   
 filter = { categoryBits = 1, maskBits = 65535 },  
 shape = { 104, 204.5 , 8, 210.5 , 57, 170.5 , 104, 184.5 }  
 }  
 }  
 }  
  
 -- Some other code...  
end  

and I initiate the object within my createScene function with this:

 local backboardShape = display.newImageRect( "assets/images/backboard.png", 286, 445 )  
 physics.addBody( backboardShape, "static", physicsData:get("backboard") )  
  
 backboardShape.name = "backboard"  

so when a collision event happens I could get the name variable of “backboard” with event.object1.name but is there any way to get the specific shape that’s stored in the pe_fixture_id variable in the above code, so I could differentiate a collision between “backboard” or “pole”?

Any help is greatly appreciated.

Thanks!
David [import]uid: 112953 topic_id: 22807 reply_id: 322807[/import]

I’ve just built a new beta version of PhysicsEditor with an improved exporter and complete example how to use fixtureIDs. The example is inside the .dmg file.

It’s available from here: - currently 1.0.9b2

http://www.physicseditor.de/download/

How does it work?

objectName = "myobject"  
  
-- create new display object  
obj = display.newImage(objectName..".png");  
  
-- remember object's type  
obj.myName = objectName  
  
-- set the physics shape  
physics.addBody( obj, physicsData:get(objectName))   
  
-- add collision handler  
obj.collision = onLocalCollision  
obj:addEventListener( "collision", obj )  

Inside the collision handler you can retrieve the shape id using the new physicsData:getFixtureId(name,index) which is now created after a new export of the physics data.

This function takes 2 parameters:

  • name - the name of the object

  • index - the element/fixture index from the collision event

[code]
local function onLocalCollision( self, event )

– retrieve fixture names from physics data
local selfFixtureId = physicsData:getFixtureId(self.myName, event.selfElement)
local otherFixtureId = physicsData:getFixtureId(event.other.myName, event.otherElement)

– print collision information
print(
self.myName … “:” … selfFixtureId …
" collision “…event.phase…” with " …
event.other.myName … “:” … otherFixtureId
)
end
[/code] [import]uid: 9611 topic_id: 22807 reply_id: 91065[/import]

Wow! Thanks for the update Andreas. I’ll try and implement the new code in the next few days. [import]uid: 112953 topic_id: 22807 reply_id: 91230[/import]

Wow, this is amazing. I was just looking at this yesterday.What you are asking for @dbokser is exactly what I was trying to do.
I see what Andreas is talking about, I’m going to go try this right now.

Basically, my world has 8 sets of 400 to 1500 vertices (vertex points that make up each part of a level). Then I have objects that are in the world, just like your example of backboard and pole.

So now you know physics editor is bad ass and Andreas makes an awesome product.

Without physics editor, my game would not be possible. Well maybe it would with 1000’s of hours trying to figure out the manual shape mapping and dealing with the 8 point limit on polygon shapes etc.

I’ll report back if it works out for me :slight_smile:

ng

[import]uid: 61600 topic_id: 22807 reply_id: 93179[/import]

Hi Andreas,

Sorry but I don´t understand this code. Could you please explain it with a sinple example. The matter is that what must be written here “self.myName”, “event.selfElement”, etc?

Thanks [import]uid: 128859 topic_id: 22807 reply_id: 120650[/import]

Hi Andreas,

Sorry but I don´t understand this code. Could you please explain it with a sinple example. The matter is that what must be written here “self.myName”, “event.selfElement”, etc?

Thanks [import]uid: 128859 topic_id: 22807 reply_id: 120650[/import]