2
\$\begingroup\$

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. What are the options to achieve this?

\$\endgroup\$
4
  • \$\begingroup\$ How many particles do you have to deal with at the same time approximately? \$\endgroup\$
    – user14170
    Mar 12, 2012 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\$
    – Saj
    Mar 13, 2012 at 2:54
  • \$\begingroup\$ @user14170 - Maybe 1000 in size to draw fire. \$\endgroup\$
    – Saj
    Mar 13, 2012 at 2:54
  • \$\begingroup\$ I take it you know Voxatron, yes? lexaloffle.com/voxatron.php \$\endgroup\$
    – o0'.
    Mar 13, 2012 at 11:20

2 Answers 2

4
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\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\$ Mar 13, 2012 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\$
    – Saj
    Mar 13, 2012 at 16:38
  • \$\begingroup\$ +1'd for the help. What would be your logic in estimating the box surronding the particle object? \$\endgroup\$
    – Saj
    Mar 13, 2012 at 16:49
  • \$\begingroup\$ That sounds like an excellent new question to ask! Going into things like that in the comments gets messy. \$\endgroup\$
    – House
    Mar 13, 2012 at 20:47
  • \$\begingroup\$ Correct answer but not as precise as the one below. \$\endgroup\$
    – user14170
    Mar 13, 2012 at 21:44
3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ So why not choosing that answer instead? ;) \$\endgroup\$
    – user14170
    Mar 14, 2012 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\$
    – Saj
    Mar 20, 2012 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .