Adding a physics body during collision

My character collides with an object that is a sensor. When he collides with the sensor object he picks it up and adds it to the image of the character. I therefor need to swap the character images which is all fine and dandy it’s just corona will refuse to allow me to add a physics body.

I have tried:
• adding the body with a delay ( tried different delays even 500 didnt work)

• using if event.phase “ended” (or whatever it is that still didnt work)

• I tried calling the function directly

I cant think of any more ideas.

Please can someone help me? here is the code:

if event.object1.name == "obj1" or event.object2.name == "obj1" then object1:removeSelf( ) local skaterY = skater.y skater:removeSelf( ) skater = nil skater = display.newImage("skater1.png") skater.x = 230 skater.y = skaterY skater.xScale = 0.3 skater.yScale = 0.3 skater.name = "james" skater.isFixedRotation = true end if event.phase == "ended" then timer.performWithDelay( 10, addSkaterPhys() ) end end

thank you

Is it a scope problem?  We can’t see where skater is defined.

Skater is a global and is defined in the create scene function

Would that be a problem?

James

Actually try this:

timer.performWithDelay( 10, addSkaterPhys )

Take the parens off of the addSkaterPhys function.  timer.performWithDelay() wants the address of the function, not the results of running the function.

Rob

You are my hero hahaha.

I’m going to write a love poem or something, been cracking at that one for hours thank you mate!

James

Is it a scope problem?  We can’t see where skater is defined.

Skater is a global and is defined in the create scene function

Would that be a problem?

James

Actually try this:

timer.performWithDelay( 10, addSkaterPhys )

Take the parens off of the addSkaterPhys function.  timer.performWithDelay() wants the address of the function, not the results of running the function.

Rob

You are my hero hahaha.

I’m going to write a love poem or something, been cracking at that one for hours thank you mate!

James