Sam Hogan
Sam Hogan

Reputation: 179

Corona SDK completely destroy physics joint

I am making a game in Corona sdk where different balls bounce and stick to each other with a weld joint. When I reset the gameplay, all joints are destroyed, then all the balls are repositioned. Here is some of my code:

--stickJoints and balls are tables that contain all the weld joints and ball objects
resetTotal = function()
    for i=1,#stickJoints do
        stickJoints[i]:removeSelf()
        stickJoints[i]=nil
    end
    for i=1,20 do
        --this resets all balls and sets linear and angular velocity to 0
        resetP(balls[i],1000+(i-1)*400,5000,0)
    end
end

The problem is that as soon as I tap the reset button, the balls that were connected temporarily interact with each other. Any thoughts are helpful. Thanks!

Upvotes: 1

Views: 233

Answers (1)

Oliver
Oliver

Reputation: 29591

I think your best bet is either

  1. to use timer.performWithDelay to call a function that will reposition the balls after the physics has had a chance to break the constraint.
  2. Remove each ball from physics, and use a delayed function cal (see item 1) to re-add them after having been repositioned.

Upvotes: 1

Related Questions