chipmunk is easy to use and do me a lot of favor.
In my program, I want to put some balls and let make them bounce inside the screen.
I create 4 static shape along the screen:
Code: Select all
cpBody *bottomBody = cpBodyNew(INFINITY, INFINITY);
bottomBody->p = cpv(0, 0);
cpShape *bottomShape = cpSegmentShapeNew(bottomBody, cpv(0, 0), cpv(320, 0), 0);
bottomShape->e = 1.0;
bottomShape->u = 0.0;
bottomShape->collision_type = 0;
bottomShape->group = 1;
cpSpaceAddStaticShape(space, bottomShape);
cpBody *rightBody = cpBodyNew(INFINITY, INFINITY);
rightBody->p = cpv(0, 0);
cpShape *rightShape = cpSegmentShapeNew(rightBody, cpv(320, 0), cpv(320, 480), 0);
rightShape->e = 1.0;
rightShape->u = 0.0;
rightShape->collision_type = 0;
rightShape->group = 1;
cpSpaceAddStaticShape(space, rightShape);
cpBody *topBody = cpBodyNew(INFINITY, INFINITY);
topBody->p = cpv(0, 0);
cpShape *topShape = cpSegmentShapeNew(topBody, cpv(0, 480), cpv(320,480), 0);
topShape->e = 1.0;
topShape->u = 0.0;
topShape->collision_type = 0;
topShape->group = 1;
cpSpaceAddStaticShape(space, topShape);
cpBody *leftBody = cpBodyNew(INFINITY, INFINITY);
leftBody->p = cpv(0, 0);
cpShape *leftShape = cpSegmentShapeNew(leftBody, cpv(0, 0), cpv(0, 480), 0);
leftShape->e = 1.0;
leftShape->u = 0.0;
leftShape->collision_type = 0;
leftShape->group = 1;
cpSpaceAddStaticShape(space,leftShape);
What I want to do now is let the ball move inside the screen from outside of the screen then bounce
inside the screen.
Is there a way to "turn off" the collision temporarily, or the ball outside the screen will first hit the "wall"
then move out of the screen.
I have tried put the ball at the edge of the screen, however when the ball move into the screen it looks like
the ball first hit the wall then into the screen (not move into the screen smoothly).
Can anyone give me some suggestion?
Thank for your help.