hi
I want to develop a game with chipmunk:
You have to draw a line before the ball falling down. And if you draw 5 lines the first should remove from the space.
My code:
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
location1 = [touch locationInView:self.view];
BEX=location1.x;
BEY=480-location1.y;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
location2 = [touch locationInView:self.view];
ENX=location2.x;
ENY=480-location2.y;
splineBody = cpBodyNew(INFINITY, INFINITY);
splineShape = cpSegmentShapeNew(splineBody, cpv(BEX, BEY), cpv(ENX, ENY), 0);
splineShape->e = 1; splineShape->u = 0.1; splineShape->collision_type = 0;
cpSpaceAddStaticShape(space, splineShape);
splineCount += 1;
if (splineCount >= 5) {
NSLog(@"deleted");
cpSpaceRemoveStaticShape(space, splineShape);
}else {
NSLog(@"newShape");
NSLog(@"%i,%i,%i,%i",BEX,BEY,ENX,ENY);
}
}
But if I do this it remove the Line i draw at the moment. So I cant draw a new line.
Is there a way to do that?
AlphaMensch