简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM