0

我创建了一个自定义类,它是一个subclassCCLayer试图将其用于CCScrollLayer

我这样做的方式是:

//Store the my layers to an NSMutableArray
for (AACustomClassLayer *cardLayer in levels) {
    [layers addObject:cardLayer];
}

在它的引擎盖下CCScrollLayer崩溃:

- (void) updatePages
{
    // Loop through the array and add the screens if needed.
    int i = 0;
    for (CCLayer *l in layers_)
    {
        l.anchorPoint = ccp(0,0);
        l.contentSize = [CCDirector sharedDirector].winSize;
        l.position = ccp(  (i * (self.contentSize.width - self.pagesWidthOffset)), 0  );
        if (!l.parent)
            [self addChild:l];
        i++;
    }
}

AACustomClassLayer 类(CCLayer 的子类)的实现如下所示:

-(id)initWithChapter:(AALevel *)level {
    self = [super init];
    if (self) {
        self.isTouchEnabled = YES;
//Here I'm adding the CCSprite to my layer

  }
    return self;
}

更新:

崩溃日志

2012-04-20 14:12:12.344 [15780:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setAnchorPoint:]: unrecognized selector sent to instance 0x884ab40'
*** First throw call stack:
(0x1a75022 0x200fcd6 0x1a76cbd 0x19dbed0 0x19dbcb2 0xd013f 0xcfe2b 0x102370 0x44c15 0xbe45f 0x8a94be 0x8aa274 0x8b9183 0x8b9c38 0x8ad634 0x282def5 0x1a49195 0x19adff2 0x19ac8da 0x19abd84 0x19abc9b 0x8a9c65 0x8ab626 0xbda06 0x22e5)
terminate called throwing an exception
4

2 回答 2

0

我找到了!

for (AACustomClassLayer *cardLayer in levels) {
    cardLayer = [[AACustomClassLayer node] autorelease];
    [layers addObject:cardLayer];
}
于 2012-04-20T11:35:00.913 回答
0

您应该在for循环中添加条件检查,以确定您从枚举中获取的对象是否实际上是 CCLayer。您的崩溃日志指出anchorPointsetter 在某些对象上不可用,大概是在您的layers_数组中的一个对象上,因为这是您发布的处理锚点的代码。

枚举很方便,但是您将所有对象都封装到CCLayer其中一个可能不是的时候。我不知道您在哪里添加对象,layers_但您是否有可能添加一个实际上不是 a 的对象CCLayer

于 2012-04-21T04:00:48.177 回答