unique collision pair functions

Official forum for the Chipmunk2D Physics Library.
Post Reply
Devnoob
Posts: 8
Joined: Mon Sep 14, 2009 2:31 am
Contact:

unique collision pair functions

Post 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
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: unique collision pair functions

Post 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.
Devnoob
Posts: 8
Joined: Mon Sep 14, 2009 2:31 am
Contact:

Re: unique collision pair functions

Post 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
User avatar
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm
Contact:

Re: unique collision pair functions

Post by Tam Toucan »

20 functions won't affect performance. It uses a hash table to store them so the number is largely irrelevant.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: unique collision pair functions

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Devnoob
Posts: 8
Joined: Mon Sep 14, 2009 2:31 am
Contact:

Re: unique collision pair functions[solved]

Post by Devnoob »

thnxs alot.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests