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.
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.
Execute the following code:
@interface GameObjectCallback : NSObject { @public GameObject *gameObject; NSString *callback; } @end @interface QueuedAction : NSObject { @public GameObject* gameObject; CCAction* action; } @end @interface GameArea2D : Recipe { NSMutableArray *bodiesToDestroy; NSMutableArray *postDestructionCallbacks; NSMutableArray *bodiesToCreate; NSMutableArray *queuedActions; } @implementation GameArea2D -(void) step: (ccTime...