I am currently working on a game using cocos2d and box2d. Let me describe my game in details:
In my game I have a main character standing on top of a building. Below the building there's this the road. Enemies pass by the road at various random speeds entering the screen from right and exiting from the left. I have created the enemies as b2_dynamicBodies and set a random velocity for each of them using SetLinearVelocity(). The main character shoots the enemies. When the projectile hits the enemies, both the projectile and the enemy are destroyed. What I want to do is that the enemies which are not shot and which move out of the screen, I want to destroy these enemies once they move out of the screen by cheking their coordinates. I have tried using world->DestroyBody(body), but it doesnt work. Pls help me with this!
p.s. I am not creating the enemies as individual distinct bodies, but I have a method which creates a body and makes it move and then I have called the method inside init with a time interval.
In my game I have a main character standing on top of a building. Below the building there's this the road. Enemies pass by the road at various random speeds entering the screen from right and exiting from the left. I have created the enemies as b2_dynamicBodies and set a random velocity for each of them using SetLinearVelocity(). The main character shoots the enemies. When the projectile hits the enemies, both the projectile and the enemy are destroyed. What I want to do is that the enemies which are not shot and which move out of the screen, I want to destroy these enemies once they move out of the screen by cheking their coordinates. I have tried using world->DestroyBody(body), but it doesnt work. Pls help me with this!
p.s. I am not creating the enemies as individual distinct bodies, but I have a method which creates a body and makes it move and then I have called the method inside init with a time interval.