Are you asking a question about collision response? You used the phrase ‘so that nothing happens pre and post collision’. I didn’t get that as it was a little vague.
Let me clarify some details about collisions…
Basic Concepts
-
Collision Detection - This is the code associated with detecting that a collision has occurred and making a decision(s) about what to do.
-
Collision Response - This is the bouncing, and sliding, pushing, and all the physics stuff you see happening.
Specific Collision Detection Events
-
preCollision - Fires just before a collision will occur. It is used to modify future collision responses or to take actions prior to said responses.
-
collision - This is your traditional collision detection logic and encompasses the exact beginning and end of the collision.
-
postCollision - Fires just after the collision has ended. Like preCollision, it is used to allow collision response changes and to handle actions that should not occur till the collision is fully completed.
Modifying Collision Responses
This is a broad topic, but it boils down to things like:
- modifying physics related object body fields like: isBodyActive, gravityScale, etc.
- Removing and adding bodies
- Modifying body quantities like velocity via method calls to setLinearVelocity(), and other physics methods.
- Pausing, stopping, and restarting physics
You are not allowed to do any of the above things while the ‘collision’ event is being processed, thus you often see people using timer.performWithDelay( … ) to make changes.
If you read this, and follow up by reading the physics guides (at top of this page under ‘See Also’ http://docs.coronalabs.com/daily/api/library/physics/index.html), all of what I said will become much clearer.