2012-06-24 27 views
0

另一種方法,我有兩個類文件hudlayer.m和actionlayer.m撥打國際長途的Cocos2D鐵漢層

我有一個方法命名爲hudlayer.m 跳,我有一個方法命名爲actionlayer jumpone。米

-(void) jumpone { 
    _heroBody->ApplyLinearImpulse(b2Vec2(_playerVelX/[_lhelper pixelsToMeterRatio], 1.25), _heroBody->GetWorldCenter()); 
} 

和hudlayer.m另一種方法稱爲跳躍

-(void)jump { 
    ActionLayer *aob = [[ActionLayer alloc] init]; 
    [aob jumpone]; 
} 

問題是,當我從actionlayer.m調用Jumpone方法我的精靈跳躍(即調用的方法)動作層

- (id)initWithHUD:(HUDLayer *)hud 
{ 
    if ((self = [super init])) { 

     [self setupWorld]; 
    } 
    return self; 
} 

我的init()方法時,我打電話通過跳轉方式jumpone來自hudlayer.m它失敗,我的應用程序崩潰。 任何幫助將不勝感激。謝謝

+0

您可以發佈ActionLayer的init方法?並從錯誤中找出一些痕跡? – giorashc

+0

我已更新init方法 – vishnu

+0

ok ...讓我們看看整個初始化... :)。嘿,還有什麼發生在jump方法中的跳過呼叫? – giorashc

回答

0

有關問題的最佳解決方案是增加一個標籤的dealloc到hudlayer &行動層

例如:hudlayer.tag = 1; actionlayer.tag = 2;

,然後只用getChildByTag這樣的:

[[[[CCDirector sharedDirector]runningScene] getChildByTag:1]jumpone]; 
+0

嗨,感謝您的回覆......但如果我添加HUDLayer.tag = 2;我得到一個錯誤「在HUDlayer對象上找不到屬性標籤」 – vishnu

+0

沒有HUDLayer.tag字面意思...我在hud層init方法中添加self.tag ...我應該已經更具體了 – skytz

+0

非常感謝它的工作現在:)兄弟我可以得到你的Skype? – vishnu

0

每次你打電話跳它創建一個ActionLayer的新實例。接下來,你建立一個新的世界,一切都會糾纏不清。此外它的內存泄漏。

讓你ActionLayer到HUDLayer的伊娃並在的HUD init方法調用

aob = [[ActionLayer alloc] init]; 

。 不要忘記釋放AOB中的HUDLayer