iosobjective-cios5cocos2d-iphoneccscrolllayer

use subclass of CCLayer for CCScrollLayer


I've created a custom class which is a subclass of CCLayer and trying to use it for CCScrollLayer

The way I do it is:

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

Under the hood of CCScrollLayer it crashes at:

- (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++;
    }
}

The implementation for the AACustomClassLayer class (subclass of CCLayer) looks like:

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

  }
    return self;
}

UPDATE:

Crash log

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

Solution

  • I've found it!

    for (AACustomClassLayer *cardLayer in levels) {
        cardLayer = [[AACustomClassLayer node] autorelease];
        [layers addObject:cardLayer];
    }