Page 1 of 1
Collision calculations
Posted:
Fri Jan 25, 2013 6:24 am
by lverona
Say, I have a bullet and several targets. Is there any performance related difference between these two variations?
a. Put all collision events into a bullet.
b. Put one collision event with bullet into every target.
Re: Collision calculations
Posted:
Fri Jan 25, 2013 7:15 am
by skydereign
I usually recommend putting it in the actor with the least number of instances, but that is just for organization purposes. If you test it, gE's collision system is smart enough, that there is no noticeable efficiency difference. I find picking a convention just makes it easier to work in gE. There is though another factor to consider. Putting it in the enemy may actually make your code easier and cleaner. Namely, if you need to reference the enemy actor's parent, or creator actor (which is more common that needing to know the bullet's parent or creator) you would want the collision event to belong to the enemy. That way you can utilize the parent/creator especial actor types.
Re: Collision calculations
Posted:
Fri Jan 25, 2013 7:23 am
by lverona
Okay, great, I did go for variant b.
I generate enemies right before view and destroy as they exit the view, so I think it should be ok performance-wise.
Is there any limit on collision events? Or if there are not many objects at the same time present in the game, then it is fine?
Re: Collision calculations
Posted:
Fri Jan 25, 2013 7:30 am
by skydereign
Collision events are reported to slow down the game. But usually that only occurs in games that have a lot of actors on the screen (and off the screen) at the same time. So I believe often the lag people experience is due to drawing images rather than the actual collisions. Though, colliding with large tiled actors does slow things down as well. As long as you clean up unnecessary actors, and your game isn't a ridiculous bullet hell type game, you should be fine.
Re: Collision calculations
Posted:
Fri Jan 25, 2013 7:44 am
by lverona
What about having lots of various events created in scripts? I mean, you know, is there a limit on how many various events you can add to the game?
Re: Collision calculations
Posted:
Fri Jan 25, 2013 7:54 am
by skydereign
Again, that would only start to be a problem if you have reached the point where the game lags due to actors. Events will normally only cause lag if they have really large loops.