How to set collision type for game like crayon ball?

Official forum for the Chipmunk2D Physics Library.
ipmart
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by ipmart »

I see, Im using different way now, the ballShapeArray is declared inside AppDelegate, I can access it now

Now im having problem with removing the ball
May I know when ball A and ball B collided, how many callback does it call?
Does it call 2 times? or only 1 time?

And can you give me example of what is the correct syntax to remove a ball?

Many thanks for your help
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by slembcke »

The callback is only called once per pair of objects.

Removing objects is covered in the docs.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ipmart
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by ipmart »

its almost working now
now the problem left is, when i remove the ball the separate callback also called and inside there i have checking that access the ball. If 1 of the ball has been removed it will be unaccesible
Im using the separate callback to update

I tried by checking all these but doesnt work

if (a->body->data != nil)
if (&a!=NULL && &b!=NULL)

Is there anyway to check if the ball is still accessible?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by slembcke »

No, that's not possible. You would have to store that somewhere else.

At least in the trunk version of Chipmunk (and I think the latest released version too) the separate callback is called as soon as you remove an object from the space. That should solve your problem. Though what exactly are you doing in the separate callback?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ipmart
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by ipmart »

im using the separate callback to update array that store connection between balls.
I determine which ball connected with which ball with that array and update it when begin and separate callback is called

Are you also doing that with the crayonball? or am i going to wrong direction?
Please help me with some tips


Many thanks
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by slembcke »

We just rebuild the array every frame using the preSolve callback. It avoids a lot of issues.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ipmart
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by ipmart »

Hi,
Thank you for the tips,
I try to remove the ball by using postStepRemove and this command:

cpSpaceRemoveBody(appDelegate.space, (cpBody *)shape->body);
cpBodyFree((cpBody *)shape->body);

cpSpaceRemoveShape(appDelegate.space, (cpShape *)shape);
cpShapeFree((cpShape *)shape);

Other ball can pass through it but the ball still visible in the display
Am I missing anything?
How do i remove the ball completely from space?

Thank you
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by slembcke »

Chipmunk doesn't know about drawing anything. You must have forgotten to remove the sprite from your scene.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ipmart
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by ipmart »

I tried to remove the sprite but still have error
The problem might be in my logic, i temporarily use moving the ball out of the display area when collision happen, it works for now

Now i need to check on how many connected balls when collision happen, I try to draw primitive line with ccDrawLine but it seems that the line is appearing behind the balls

Is there anyway to draw primitive line in front of the ball?

Thanks
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set collision type for game like crayon ball?

Post by slembcke »

You should ask these questions in the Cocos2D forums. While a few people here use Cocos2D, you will get much better answers there.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests