0
\$\begingroup\$

I'm trying spawn collidable debris from a ship when it explodes in love2d/box2d, however, World:isLocked() is true when collision callbacks are called:

This will return true inside the callbacks from World:setCallbacks. (source)

So creating a new body throws an error. Are there any workarounds for this?

\$\endgroup\$
1
\$\begingroup\$

The usual way to solve this is to create the objects once the physics-simulation has completed.

In your collision callback you would push all the objects you want to create into a list-like data-structure. Once your physics-simulation-step is complete (eg. after world:update), create the objects/bodies that have been pushed to the list (thereby removing them from the list, so that they don't get created multiple times).

\$\endgroup\$
  • \$\begingroup\$ OK, I guess that is the simplest way to do it then. Thanks :D \$\endgroup\$ – CharlesL Nov 27 '13 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.