Chipmunk physics accessing shapes in multiple methods issue
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. :
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 : -
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.
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.
Thanks in advance
JinnoRb
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.
Thanks in advance
JinnoRb
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Accessing iOS Folders | scarypajamas | 4 | 5,319 |
Oct 17, 2011 02:52 PM Last Post: scarypajamas |
|
| Accessing a method from anywhere in the project... Help! | SamBaylus | 5 | 3,994 |
Feb 4, 2010 09:24 AM Last Post: kendric |
|
| Drawing Anti-Aliased Shapes With Open GL | muleskinner | 4 | 3,447 |
Nov 17, 2009 10:01 AM Last Post: warmi |
|
| Accessing the GCC compiler flags | Madrayken | 6 | 5,322 |
Sep 19, 2009 01:18 AM Last Post: OneSadCookie |
|
| Drawing shapes opengl es | jjslay | 2 | 3,369 |
Aug 14, 2009 11:07 AM Last Post: jjslay |
|

