【问题标题】:Calling Parent Methods Cocos2d调用父类方法 Cocos2d
【发布时间】:2012-04-17 04:28:08
【问题描述】:

我正在尝试从层调用方法。有问题的方法在该层的父级中。

示例:

“生存”是我场景的名称 “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;
}

生存.m

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

文本“test”从未出现在日志中,但调用了我层中的方法。问题是即使发送了对该方法的调用,它也永远找不到该方法,并且什么也没有发生。 我没有收到任何错误消息。

我已经尝试了所有我知道的方法,所以请你给我一些建议,或者指出问题。

【问题讨论】:

    标签: ios cocos2d-iphone parent-child layer scene


    【解决方案1】:

    也许这会有所帮助 [(ParentClassName*)[self parent] functionName];

    【讨论】:

      【解决方案2】:
       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");
       }
      

      问候, 尼尔。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-14
        • 2011-01-03
        • 2017-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多