I made a class in objective-c and I made an instance in another class my code looks like this…
#pragma mark - HelloWorldLayer
@interface HelloWorldLayer()
-(void) initPhysics;
@end
@implementation HelloWorldLayer
-(id) init
{
if( (self=[super init])) {
// init physics
[self initPhysics];
//THE CLASS I'M HAVING TROUBLE WITH
id player;
player = [Blob new];
//SAYS SET NODES CAN'T BE FOUND
[player setNodes];
[self scheduleUpdate];
}
return self;
}
-(void) initPhysics
{
//BLAHBLAHBLAH
}
-(void) draw
{
//BLAHBLAHBLAH
}
-(void) update: (ccTime) dt
{
//BLAHBLAHBLAH
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//BLAHBLAHBLAH
}
@end
#pragma mark - HelloWorldLayer
@interface Blob()
-(void) setNodes;
@end
@implementation Blob
-(void) setNodes;
{
b2BodyDef bodyDef;
b2Body *body;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(100/PTM_RATIO,100/PTM_RATIO);
body = world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2CircleShape circle;
circle.m_radius = 32/PTM_RATIO;
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &circle;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.5f;
fixtureDef.restitution = 0.0f;
body->CreateFixture(&fixtureDef);
}
@end
I am coding a game with cocos2d and box2d for the iphone and I took out most of the bulk code. But I am having a problem with the blob class. I create an instance named player and try to call the function “setNodes” And my problem is every time I compile it gives me a warning that setNodes cant be found… I feel like I did something wrong because I know it’s there… Objective-c is skrewwy I’m a C++ man, thankyou 🙂
setNodesshould be declared before the line:You probably should declare your classes in an .h file and import it, like you do in C++.
Or at least, put the declaration of Blob before the implementation of HelloWorldLayer