Asynchronous body destruction
So far, we have learned how to create bodies, how to reposition them, and how to apply forces and impulses to move them around onscreen. In this example, we will see how to destroy a body during the physics simulation. This is naturally a very tricky process that can create bugs and cause game crashes if you're not careful.
Getting ready
Please refer to the project RecipeCollection02 for full working code of this recipe. Also note that some of the following code has been omitted for brevity.
How to do it...
Execute the following code:
@interface GameObjectCallback : NSObject { @public GameObject *gameObject; NSString *callback; ...
Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.