local vs global physics collision listeners

Wondering what the best performance is between using local and global. From the API docs, it says this -

local:
[lua]crate1.collision = onLocalCollision
crate1:addEventListener( “collision”, crate1 )[/lua]

global:
[lua]Runtime:addEventListener( “collision”, onCollision )[/lua]

For my project, I have about 5-6 different types of objects (player, bullet, enemy, obstacle, etc.), and roughly 30-40 of them on screen at any given time. Currently I have local listeners on each physics object.

Would it make more sense to just register a single global collision listener instead? [import]uid: 49447 topic_id: 19494 reply_id: 319494[/import]

It really depends on your app, whether or not either or would yield better performance over the other.

My best suggestion would be to set up individual collision listeners for each object, and do extensive on-device testing for performance.

Then, comment out that code and do the same testing using a global collision listener. If both perform the same, then the decision boils down to personal preference. But if one yields better performance than the other, then you should obviously go with the better performing one. [import]uid: 52430 topic_id: 19494 reply_id: 75270[/import]

Thanks, I was just wondering if there was any other way of predicting which would be better before actually implementing.

I’ll be sure to report back with my own findings in case it helps anyone else out. [import]uid: 49447 topic_id: 19494 reply_id: 75291[/import]

My vote is for global listeners at least for the majority of you physics objects. So lets say all you pieces “basically” do the same thing during a collision like turing different colors. It would make more sense to make a global listener. Then if you had certain pieces that had unique actions like changing shape and shooting lasers, then you would make a local listener for that objects. So if you had 50 pieces and 10 special pieces, instead of having 60 instances of listeners, you would only have 1 global listener for the 50 pieces and 10 locals for the special pieces.

Early on I used local listeners for every piece and was getting horribly slow response time in my game which I attributed to messy code. So then I made a global listener and which under different circumstances pointed to table functions of the pieces. Still no difference. It wasn’t until I packed all the functionality I needed into the global listener that I gained the most in performance. Now my game plays almost too fast on my devices, and am now thinking of ways of slowing it down lol. [import]uid: 54716 topic_id: 19494 reply_id: 75314[/import]

For me Runtime is the way to go, one function that manages collision for all objects. [import]uid: 84637 topic_id: 19494 reply_id: 75362[/import]

I wanted to ask the same exact question. So Runtime collision it is. The only thing I did not get is in regards to:

“…So then I made a global listener and which under different circumstances pointed to table functions of the pieces. Still no difference. It wasn’t until I packed all the functionality I needed into the global listener that I gained the most in performance…”

I am sorry I must be missing something but what exactly did you do to make the app too fast ( nice problem to have by the way:). I will you assume that by global listener you meant Runtime collision listener ( versus a local one) but I do not get the packing of functionalities part.

I am sorry if this a stupid question;(

Thanks.

Mo. [import]uid: 49236 topic_id: 19494 reply_id: 76706[/import]