2012-04-17 44 views
0

我想打电话从层的方法。有问题的方法在该图层的父级中。调用父方法的Cocos2D

实施例:

“生存” 是我的场景 的名称 “SSpriteLayer” 是我层的名称

SSpriteLayer.m

//this id not my actual method, just a simplified version 
-(void) spritePick { 
[scene initSpritePick]; 
NSLog(@"sent"); 
{ 

SSpriteLayer.h

#import Survival 
@interface SSpriteLayer : CCLayer { 
Survival *scene; 
} 

Survi val.m

- (void) initSpritePick { 
NSLog(@"test"); 
} 

文本“测试”从不出现在日志中,但我的图层中的方法被调用。问题是,即使调用方法被发送,它永远不会找到该方法,也没有任何反应。 我没有收到任何错误消息。

我都想尽办法做到这一点,我知道,所以请您能不能给我一些建议,或者指出问题所在。

回答

0
Try using Class Method it will work 

实施例:

"Survival" is the name of my scene "SSpriteLayer" is the name of my layer 

**SSpriteLayer.m** 

//this id not my actual method, just a simplified version 
-(void) spritePick 
{ 
    [Survival initSpritePick]; 
    NSLog(@"sent"); 
    { 
    } 


**SSpriteLayer.h** 

#import Survival 
@interface SSpriteLayer : CCLayer { 
    Survival *scene; 
} 

**Survival.m** 

    + (void) initSpritePick 
    { 
     NSLog(@"test"); 
} 

问候, 尼尔。

+0

感谢您的快速答复! – akuritsu 2012-04-17 05:50:52

1

也许这可以帮助 [(ParentClassName *)自父] functionName]。