不能

2012-02-18 70 views
0

我做了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++的人,三江源:)

回答

2

setNodes應行前聲明:

[player setNodes]; 

你或許應該在.h文件中聲明你的類和導入,就像你在C++中做的一樣。

或者至少,把一滴的聲明HelloWorldLayer

@interface Blob() 
    -(void) setNodes; 
@end 

@implementation HelloWorldLayer 
// ... 
+0

OMG ......我聲明,我的定義執行前......那傢伙那麼補救三江源這麼多<3我有這麼趕上了在我學習語言時我猜 – 2012-02-18 01:23:25