2014-06-06 33 views
0

我想從Cocos2D中的另一個類訪問我的自定義方法。這是我之前用Cocos2D完成的一些事情,但由於某些原因,它現在不能工作。從Cocos2D中的另一個類訪問方法

heroNode.h(CCNode)

@interface heroNode() 

    -(void) staminaCounter; 

@end 

#import "heroNode.h" 

@implementation heroNode { 
} 
     -(void)staminaCounter { 
     //My Code Here 

    } 
@end; 

MainScene.h(CCScene)

#import "heroNode.h" 

@implementation MainScene 
{ 
    heroNode *HeroStuff; 
} 

//Using 
    HeroStuff = [[heroNode alloc] init]; 

//Then this is where I am having the issue calling `staminaCounter` 
//Do something like 
//[heroStuff staminaCounter]; 

回答

0

中聲明 「heroNode.h」 -(void)staminaCounter,因爲如果你不這樣做它,該方法是私人的,你只能在你的課堂內使用它。

之間@interface@end

+0

哎呀對不起,我已經做到了。使用'[heroStuff staminaCounter];'不起作用 – memyselfandmyiphone

+0

你不能做[heroNode staminaCounter],你已經定義了HeroStuff變量,所以你必須做[HeroStuff staminaCounter]。順便說一下......你的班級的第一個字母應該是大寫(HeroNode),而不是你的變量(heroStuff)。 – gabuh

+0

我正在使用heroStuff,它不起作用。我得到錯誤'不可見的@interface聲明.....' – memyselfandmyiphone

相關問題