Ideas on adding sound

Official forum for the Chipmunk2D Physics Library.
Post Reply
mugatu
Posts: 2
Joined: Wed Apr 23, 2008 1:57 am
Contact:

Ideas on adding sound

Post by mugatu »

Hi,

i was wondering if anyone has any ideas/suggestions about adding sound to a physic based game (or playground, think 'Phun' without the water). I think that not every collision should have a sound, or everything will be making an annoying noise all the time. Maybe filter by the force resulting of the colission? Is this possible with chipmunk? .... any suggestions?

Thanks in advance.
Michael Buckley
Posts: 46
Joined: Tue Aug 21, 2007 10:30 am
Contact:

Re: Ideas on adding sound

Post by Michael Buckley »

Yeah, that's very possible. You can implement use a collision function to do processing on collisions. First, define a function returning an int, with the paramaters (cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data). Basically, you want to make sure the function returns 1 if you want the two objects to actually collide, and 0 if you don't. In the function, you can use the cpShapes a and b to get the weight or speed of their respective bodies, or whatever else you wanted to test for before playing a sound. cpShape also has a void pointer called data which you can use to point to anything you want, so when constructing shapes, you could, for example, give them all names, and only play collisions between certain names. That would be kinda slow though. It's just meant to be an example.

Finally, when you have created the function, you use cpSpaceAddCollisionPairFunc or cpSpaceSetDefaultCollisionPairFunc to define that function as the collision function for that space. The documentation has more details.
mugatu
Posts: 2
Joined: Wed Apr 23, 2008 1:57 am
Contact:

Re: Ideas on adding sound

Post by mugatu »

Thank you very much, i'll look into it.
Post Reply

Who is online

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