What's better for performance...

I have a body that is the main "character." I then have multiple small bodies that it "collects" (you know, like gems or something like that for extra points). There are then many other bodies also. Now, I was wondering--Which option is better for performance:

1. Put a preCollision event handler on the "character" that interacts with multiple other objects?
or
2. Put a preCollision event handler on the multiple "collectors' items" that interact only with the "character"?

So basically have one body with multiple collision calls or multiple bodies with few collision calls?

Thanks! Sorry if that was confusing.

I believe that using one body with a couple of collision calls is better than giving every single item you spawn a listener for a collision event ;)

preCollision events are much more processor intensive since they tend to get triggered much more frequently than regular collision events so you should use as few as possible. It would be better performance wise if you were able to use regular collision events instead if possible.

Yes, @calebr2048 is right on! To give you a sense of scale, I've seen apps where preCollision events occurred 10,000 times as often as a regular collision event --- for just one single render pass (it'd repeat for the next render pass)

Hmmmm...Thanks for the thoughts. I think I need a preCollision event because from the docs it sounds like that is the only place to make isSensor=true and allow the object to pass through the other without a hiccup. Am I right about this?

Thanks for the replies!

I tested my own theory and it seems like you can pass isSensor in the onCollision event handler. So I am going to drop the preCollision handler and go ahead with that. Thanks!

views:1516 update:2011/9/28 8:56:32
corona forums © 2003-2011