I am using CCParticleSystemQuad to create particle effects. But I want my sprites to be able to collide with particles. Say your character is a dragon, the dragon breath is a particle effect emitting fire. When the breath hits objects (sprites), I should be able to know it collided with some sprites. How can it be done? Unfortunately google search on this subject doesn't give very good output.

  • \$\begingroup\$ How many particles do you have to deal with at the same time approximately? \$\endgroup\$ – user14170 Mar 12 '12 at 22:14
  • \$\begingroup\$ @Byte56 - I thought of that. But when you create fire, you don't have the particles surrounding in exact polygonal shape with NO spaces in between. Can you direct me to an example please? \$\endgroup\$ – DragonBorn Mar 13 '12 at 2:54
  • \$\begingroup\$ @user14170 - Maybe 1000 in size to draw fire. \$\endgroup\$ – DragonBorn Mar 13 '12 at 2:54
  • \$\begingroup\$ I take it you know Voxatron, yes? lexaloffle.com/voxatron.php \$\endgroup\$ – o0'. Mar 13 '12 at 11:20

Pixel perfect collision with particles would be very CPU intensive, this would be even worse on a mobile device. You may want to cheat and use a bounding shape to surround the area the particles occupy, and use that bounding shape for collision purposes. This doesn't have to be exact. It's an approximation of the area the particles occupy. I imagine if you actually implemented this and tested it you'd find that it was sufficient for your needs.

  • \$\begingroup\$ +1. Or use bounding circles for each particle - although that might still be slow on a mobile platform. Spatial hashing could also be fast. \$\endgroup\$ – Jonathan Dickinson Mar 13 '12 at 11:04
  • \$\begingroup\$ @Byte56 - That's what I did but it doesn't look real sometimes when the paticles are not appearing in some space of the box but a collision gets still registered. Maybe my logic was not that good. I estimated the size of the particle object and hard coded. \$\endgroup\$ – DragonBorn Mar 13 '12 at 16:38
  • \$\begingroup\$ +1'd for the help. What would be your logic in estimating the box surronding the particle object? \$\endgroup\$ – DragonBorn Mar 13 '12 at 16:49
  • \$\begingroup\$ That sounds like an excellent new question to ask! Going into things like that in the comments gets messy. \$\endgroup\$ – MichaelHouse Mar 13 '12 at 20:47
  • \$\begingroup\$ Correct answer but not as precise as the one below. \$\endgroup\$ – user14170 Mar 13 '12 at 21:44

The exact answer would be a somewhat Point-In-Polygon algorithm but as mentioned above it will be very (very) time-consuming in real-time and would be more used for simulation purpose.

Most of the time in real-time you can approximate this by using either :

It basically all depends of the average behavior of the shape made by all your particles.

  • \$\begingroup\$ So why not choosing that answer instead? ;) \$\endgroup\$ – user14170 Mar 14 '12 at 10:17
  • \$\begingroup\$ Becuase this - "You may want to cheat and use a bounding shape to surround the area the particles occupy, and use that bounding shape for collision purposes." solved my problem without losing several fps. But I appreciate your links as they are quite informative. \$\endgroup\$ – DragonBorn Mar 20 '12 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.