## Chipmunk physics accessing shapes in multiple methods issue

Nibbie
Posts: 1
Joined: 2010.03
Post: #1
Hello all,

I'm brand new to iphone development and I (Probably stupidly) decided to jump in at the deep end.

I have what is probably a very simple issue to fix, but with my general newbieness its giving me on hell of a headache.

Basically I have a simple physics based game running where you're trying to make all the balls fall off the screen by removing the blocks in the way.

My issue is I can't for the life of me get the blocks to remove properly from anything other than the method I've declared the shapes (And bodies) in, if I try to do so it gives me 'ballBody' and 'ballShape' undeclared errors.

So effectively I have the game kicking off, when I hit the start button it calls a method that declares and programatically builds the sprites, then assigns the chipmunk physics shapes and interaction bodies onto it. :

Code:
```- (void)setupChipmunk {     //start Chipmunk          cpInitChipmunk();          //Create a space object          space = cpSpaceNew(); // Create our ball's body with 100 mass // and infinite moment     //                              mass    moment     cpBody *ballBody = cpBodyNew(100.0, INFINITY);      // Set the initial Position                 //Width, Height     ballBody->p = cpv(60, 250);      // Add the body to the space          cpSpaceAddBody(space, ballBody);          //Create our shape associated with the ball's body              cpShape *ballShape = cpCircleShapeNew(ballBody, 20.0, cpvzero);          ballShape->e = 1.0; //Elasticty          ballShape->u = 0.8; // Friction          ballShape->data = ball; //Associate without ball's UIImageView                                //    cpShape *ballShape = cpCircleShapeNew(ballBody, 20.0, cpvzero);          // Add the shape to out space          cpSpaceAddShape(space, ballShape); }```

For the sake of it I've only taken the 'ballShape' code which is the one I'm trying to delete when touched currently.

Then within the touchesBegan method I have : -

Code:
```- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject];     if(ball.center.y > self.view.bounds.size.height) {                  if(ball.center.y > self.view.bounds.size.height + 10) {                         score_int = score_int + 1;             score.text = [NSString stringWithFormat:@"%d",score_int];                              cpSpaceRemoveBody(space, ballBody);             cpSpaceRemoveShape(space, ballShape);                                       [ball removeFromSuperview];                                       } }```

Which currently fires off 'ballBody' and 'ballShape' undeclared errors.

These two lines of code are what I need to disable the body & shape (And so turn off the representation of the sprite I'm using.

Code:
```cpSpaceRemoveBody(space, ballBody); cpSpaceRemoveShape(space, ballShape);```

I'm guessing its going to be a simple call in the header of the method to access the instance variables, but I can't work out what it is

Any help would be much appreciated, really ripping my hair out with this one.