Hi,
I need help in destroying the sprites which are in and around the collided sprites ie in a radius of 2.5 cms all sprites should be destroyed. Idea here is i will be shooting a projectile from bottom to the objects falling from the top. Once collision happens all the sprites around that radius also should be destroyed. Like a Bomb Effect. I have used box2d for collision ie contact listener. How to go about doing that?
Please Suggest 🙂
Regards,
Karthik
I think the best thing you can do here is a query; if you look in the Mouse Joint examples in the testbed, you'll see the part where the program grabs an object that is within a small area around the mouse point. You can adapt the same technique to find shapes close to an object.
Note though, that the AABB code (in 2.1.2 anyway) is not very accurate, and after you've collected shapes that are close enough to the target you might want to do an additional distance check ((explosion world center - body world).length) to verify that the bounds are indeed correct.
You could also skip the AABB part and just go for a direct length comparison between each entity and the explosion point. Whichever you prefer, although I'd imagine the first method would be faster and filter out the entities that aren't in the same island/proxy/whatever they are called.
The only thing missing from this method, directly anyway, is that you won't find any shapes that might be blocking it (like, if the explosion is behind a wall and the sprite is in front of the wall it'll still be counted). You can do a raycast then between the two shapes to find out if anything may be in its path.
-P
Thank You for your reply. However i'm pretty new to Xcode and Box 2d. I did try to find out more about AABB code and on how to use mouse joints couple of days back. Got confused a bit. If its possible for you to gimme links of where mouse joints are used or a sample code would be really helpful. I just need a head start on how to start coding for this
Regards,
Karthik
Wow!! Thanks Buddy. I will get to work on this as i have a fair idea. I will repost for any concerns 🙂
Regards,
Karthik