[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Simple way to remove on collision

Simple way to remove on collision

Official forum for the .

Simple way to remove on collision

Postby Sloth » Sun Apr 04, 2010 7:53 pm

Hey,

Sorry if this is a really simple / dumb question, but I've been looking into the documentation and can't find anything other than the integrated cocos2d spacemanger to do what I want.

I'm looking for the ability to remove a shape on collision with a static object simply put.

I'm messing about with iphone development and don't want to use cocos2d. I'm also using an NSTimer to iterate my simulation, so what would be the best way of removing a shape when it collides with a specific static shape?

Anyone that helps gets a cookie :D

Thanks.
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Re: Simple way to remove on collision

Postby Sloth » Sun Apr 04, 2010 7:54 pm

Oh may I add I don't think I'm on the latest version of chipmunk. Didn't realise there was a new one until just now! :D, so if it can be in the non objective-C syntax that'd be great.
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Re: Simple way to remove on collision

Postby slembcke » Sun Apr 04, 2010 7:59 pm

Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simple way to remove on collision

Postby Sloth » Wed Apr 07, 2010 3:18 pm

Thanks :)

I'm probably being really dumb but I can't seem to get it to work though :(

Thus far I have the two shapes being created in the same method, each set to their own collision type (5 for the shape I want to disappear and 6 for the one which is static)

I've then made collisionHandler, which is declared in the same method that these shapes are created :

cpSpaceAddCollisionHandler(space, 6, 5, begin, NULL, NULL, NULL, NULL);

then this declared


static void begin(cpArbiter *arb, cpSpace *space, void *ignore)
{
cpShape *goShape, *staticShape; cpArbiterGetShapes(arb, &goShape, &staticShape);

cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, goShape, NULL);

}

static void
postStepRemove(cpSpace *space, cpShape *shape, void *unused)
{
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);

cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}




This now makes it crash out when the two shapes collide. I know its going to be something simple but any help!? :(
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Re: Simple way to remove on collision

Postby slembcke » Wed Apr 07, 2010 4:09 pm

Your shape types are swapped. The order returned by cpArbiterGetShapes() is the same as set by cpSpaceAddCollisionHandler(). Also, you should use an enumeration or static variables for your shape types. Once you have more than like 3 of them it can become difficult to keep track of them all just by number.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simple way to remove on collision

Postby Sloth » Wed Apr 07, 2010 5:12 pm

Gotya! :D

So say I wanted to remove the sprite as well and +1 in a label, how do I get it to call through? Currently I can't get the method to communicate with anything externally, it simply removes the shape & body currently.
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Re: Simple way to remove on collision

Postby slembcke » Wed Apr 07, 2010 6:23 pm

Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simple way to remove on collision

Postby Sloth » Thu Apr 08, 2010 7:22 am

is the 'World *World' made up of a struct that would be declared in the header?
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Re: Simple way to remove on collision

Postby slembcke » Thu Apr 08, 2010 8:40 am

Not knowing what language you are using, I just made it look C++ish. It doesn't really matter if you are using a struct or object or whatever, but yes it would have to be declared in a header for it to be usable in any C-like language.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simple way to remove on collision

Postby Sloth » Sat Apr 10, 2010 10:46 pm

I'm starting to feel like a complete dummy now :(

I have this almost all working within Objective-C now, (using the C++ methods as shown above)

I still for whatever reason can't seem to make a simple UILabel increment by 1 when one of these objects collide. I'm not really sure why it doesn't work quite honestly :(

Any help?
Sloth
 
Posts: 9
Joined: Sun Apr 04, 2010 7:49 pm

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests

cron