Hi -
Scenario:
I am developing a game similar to the game ‘float’ where objects are spawned at the top and fall to the ground due to gravity. The game objective it to touch the objects to keep them from falling down. In the process they bounce against other spawned objects. If they touch the ground the objects are removed.
Problem:
My code reliably handles multiple objects hitting the ground and they get removed correctly (without crashing the physics engine). But when I touch an object and try to apply applyLinearImpulse to the object, it crashes the physics engine (all physics bodies vanish from the screen).
This happens pretty randomly. I have tried all the suggestions that I found on these forums.
including suggestions from
http://jonbeebe.tumblr.com/post/2515495262/corona-collision-no-no
The basic concept is to minimize collision events which I have accomplished using collision filters. So I have eliminated most collision events between the objects. The only collision event that is triggered is, when the objects touch the ground.
In the actual touch event on the object (each object has its own collision event handler), I store the movement to be applied to the object and set a one time timer (after 1 ms). In that timer event handler, I pause the physics engine, make my changes to the object (applyLinearImpulse) and then restart the physics engine. (I tried setting object.is BodyActive = false instead of pausing physics and still got the same random crashes)
I have added lineardamping and angular damping to all objects to slow them down a bit.
But is seems like whatever I do, under some conditions (the objects are bouncing against each other and some are getting removed while hitting the ground), my move timer fires while physics engine is still calculating and this causes a crash. If I reduce the objects to about 5, that reduces the probability of crashes but they do happen randomly.
Is there a definitive way in corona to move objects while objects are controlled by physics? [import]uid: 21208 topic_id: 17482 reply_id: 317482[/import]
[import]uid: 52491 topic_id: 17482 reply_id: 66390[/import]