我在objective-c中创建了一个类,我在另一个类中创建了一个实例,我的代码看起来像这样......
#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
我正在使用cocos2d和box2d为iphone编写游戏,我拿出了大部分批量代码。但是我遇到了blob类的问题。我创建一个名为player的实例,并尝试调用函数“setNodes”而我的问题是每次编译它都会给我一个警告,即setNodes无法找到...我觉得我做错了,因为我知道它在那里.. Objective-c是skrewwy我是一个C ++人,谢谢你。)
答案 0 :(得分:2)
setNodes
应该在行之前声明:
[player setNodes];
您可能应该在.h文件中声明您的类并导入它,就像在C ++中一样。
或者至少,在实施HelloWorldLayer
之前放置Blob的声明@interface Blob()
-(void) setNodes;
@end
@implementation HelloWorldLayer
// ...