Page 1 of 1

unique collision pair functions

Posted: Sun Oct 18, 2009 5:23 am
by Devnoob
hi.
i have a game on IPhone with several enemies categories ,and several enemies in each category and i want to add a collisionpairfuction to handle collisions.

ex cpSpaceAddCollisionPairFunc(space , 200, B, &A_B_Coll,self);
and then in A_B_Coll
{
fireBulletToA;
cpSpaceRemoveCollisionPairFunc(space , 200, B);
return 0;
}
[/code]
A is the enemy collision_type = 200 .... i ve got 20 enemies of A do i have to make a different collision_type for each one ?
B is a defence tower with circle Shape to detect collision

1-do i have to make a different collision_type for each one ?
2- if i added cpSpaceAddCollisionPairFunc(space , 200, B, &A_B_Coll,self); 20 times can i stop it for a specific enemy ex A11

Re: unique collision pair functions

Posted: Sun Oct 18, 2009 12:57 pm
by maximile
No, probably best to just have one collision function for all your enemies. Then in your function just check which enemy hit the tower (or whatever). No need to remove the collision function either; change a value instead (e.g. hasBeenHit = YES) and then test for it in the function (e.g. if (hasBeenHit == YES) return;).

Hope that gives you some idea. Having lots of collision functions would be possible but probably tricky and inelegant.

Re: unique collision pair functions

Posted: Thu Oct 22, 2009 4:19 am
by Devnoob
hmmm what if i added 20 collision pair functions , will this decrease the performance (i will remove the pair function on collision)
note developing for the iphone

Re: unique collision pair functions

Posted: Thu Oct 22, 2009 7:07 am
by Tam Toucan
20 functions won't affect performance. It uses a hash table to store them so the number is largely irrelevant.

Re: unique collision pair functions

Posted: Thu Oct 22, 2009 8:17 am
by slembcke
It does the hashtable lookup for every pair of colliding objects anyway, even when there are no collision functions registered. It's not very expensive at all.

Re: unique collision pair functions[solved]

Posted: Wed Oct 28, 2009 1:55 am
by Devnoob
thnxs alot.