[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 - How to set collision type for game like crayon ball?

How to set collision type for game like crayon ball?

Official forum for the .

How to set collision type for game like crayon ball?

Postby ipmart » Fri Apr 23, 2010 11:58 pm

Hi all,

Im a newbie in chipmunk and must say im very impressed with the physics engine, great work :shock: :shock: :shock:

Im having problem with a collision type.
I'm trying to detect a collision between balls with many different color, very similar to crayon ball
http://howlingmoonsoftware.com/iPhoneCrayonball.php

I set all balls to have collision type 1 and add cpSpaceAddCollisionHandler like this:
cpSpaceAddCollisionHandler(space, 1, 1, &collisionBegin, &collisionPreSolve, nil, &collisionSeparate, self);

But all balls doesnt collide with each other.

How do you set the collision type and cpSpaceAddCollisionHandler to achieve same thing like crayon ball?


Many thanks
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby slembcke » Sun Apr 25, 2010 12:35 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: How to set collision type for game like crayon ball?

Postby ipmart » Mon Apr 26, 2010 3:03 am

Thank you for replying,

I tried that but balls with same color doesnt collide with each other
only balls with different color will collide, the same color ball pass through each other.

How can i fix this?

Thanks in advance
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby ipmart » Mon Apr 26, 2010 5:27 am

oh i found the problem, its because im returning 0 in the presolve function thats why the ball pass through
Silly me :roll: :roll:

oh ya another thing, would you mind to give me tips on how to detect 3 balls in same color touching each other?

Thanks in advance
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby slembcke » Mon Apr 26, 2010 8:58 am

What you are looking for is how to find connected components of the graph. http://en.wikipedia.org/wiki/Connected_ ... aph_theory)
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: How to set collision type for game like crayon ball?

Postby ipmart » Tue Apr 27, 2010 11:35 am

Thank you for replying

Im trying to figure out the structure now.
Meanwhile im having problem accessing variable that passed as user data like this:

I set the handler this way
cpSpaceAddCollisionHandler(space, sheetCounter, sheetCounter, &collisionBegin, nil, nil, &collisionSeparate, self);
self is ccLayer

int collisionBegin(cpArbiter *arb, cpSpace *space, void *data)
{
CCLayer *myLayer = (CCLayer *)data;
int ballShapeArrayCount = [myLayer.ballShapeArray count]; <--- this one error: request for member 'ballShapeArray' in something not a structure or union

}

please let me know what error that i make


Many thanks
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby slembcke » Tue Apr 27, 2010 12:33 pm

That's a compiler error. First of all, are you sure the specific type is a CCLayer? By doing myLayer.ballShapeArray you are asking for the ballShapeArray property of CCLayer. If the property is defined on a subclass, you'll need to cast it to that class first. If you meant to get a field you need to use the '->' operator, and you also need to cast it to the correct class first.
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: How to set collision type for game like crayon ball?

Postby ipmart » Wed Apr 28, 2010 2:23 am

im passing self which is a CCLayer class into user data

I tried this
CCLayer *myLayer = (CCLayer *)data;
BallShape *myArray = (BallShape *)myLayer.ballShapeArray;
it come out with this error: request for member 'ballShapeArray' in something not a structure or union

if i change to this
CCLayer *myLayer = (CCLayer *)data;
BallShape *myArray = (BallShape *)myLayer->ballShapeArray;
this error: 'struct CCLayer' has no member named 'ballShapeArray'

please give me example of how do you access data variable if you pass in ssLayer into the user data field

Many thanks
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby ipmart » Wed Apr 28, 2010 2:51 am

Here is the header of ballshape.h

#include <stdlib.h>
#import <Foundation/Foundation.h>
#import "chipmunk.h"
#import "cpShape.h"

@interface BallShape : NSObject {

cpShape *shapePointer;

}

@property (nonatomic) cpShape *shapePointer;

@end



and the implementation:
#import "BallShape.h"


@implementation BallShape

@synthesize shapePointer;

@end


I use this class to wrap cpshape pointer so i can add into nsmutablearray
ipmart
 
Posts: 12
Joined: Fri Apr 23, 2010 11:36 pm

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

Postby slembcke » Wed Apr 28, 2010 9:09 am

Looks like CCLayer is the Cocos2D layer class. Unless you changed the Cocos2D source, it is not going to have a field or property named ballShapesArray. What class was self? In order to call a property or use the -> operator, the compiler needs to know the precise class of the object you are calling it on. Neither can be used dynamically, it won't give you a warning like calling an unknown method, it's just a hard error.
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

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests

cron