Understanding callbacks
Posted: Wed Feb 17, 2010 12:29 am
I have a simple app with balls falling down the screen and landing in buckets. The buckets are simply rectangular areas with three static shapes for the two sides and bottom. I also have a sensor shape (rectangle) that fills the inside of the bucket.
I attached callback functions to handle collisions between balls and the sensor. The balls start out purple. The Begin callback causes them to turn yellow (ball enters bucket) and the Separate callback turns them back to purple (ball bounces out of bucket). I would expect all balls in the bucket to be yellow at the end. This is mostly true, but I will occasionally get one or two balls that end up purple inside the bucket.
To find out what's going on, in the Separate event I changed the collision_type of the ball to some other value. That way I can track what happens to it next. I would expect that the next callback to get invoked for that particular ball to be a Begin event, yet I am seeing the PreSolve event is actually called, meaning the ball is actually still inside the bucket. This is likely why the ball is staying purple.
I'm somewhat new to Chipmunk so this might just be me not understanding how things work. I suspect what is happening is the solver is predicting that the ball and bucket will separate, and thus call the Separate callback, while instead other collisions cause the ball to actually remain in the bucket.
I hope I've explained all that sufficiently. Since I mostly understand what is happening (if not why) I think I can work around it, but it would still be nice to know whether or not this is expected behavior.
I attached callback functions to handle collisions between balls and the sensor. The balls start out purple. The Begin callback causes them to turn yellow (ball enters bucket) and the Separate callback turns them back to purple (ball bounces out of bucket). I would expect all balls in the bucket to be yellow at the end. This is mostly true, but I will occasionally get one or two balls that end up purple inside the bucket.
To find out what's going on, in the Separate event I changed the collision_type of the ball to some other value. That way I can track what happens to it next. I would expect that the next callback to get invoked for that particular ball to be a Begin event, yet I am seeing the PreSolve event is actually called, meaning the ball is actually still inside the bucket. This is likely why the ball is staying purple.
I'm somewhat new to Chipmunk so this might just be me not understanding how things work. I suspect what is happening is the solver is predicting that the ball and bucket will separate, and thus call the Separate callback, while instead other collisions cause the ball to actually remain in the bucket.
I hope I've explained all that sufficiently. Since I mostly understand what is happening (if not why) I think I can work around it, but it would still be nice to know whether or not this is expected behavior.