ios - Why is an init method of a child not called by a parent allocating that child in cocos2d v2.0? -
i have class:
//interface @interface savingdataplist : simpletimedgamerecipe { nsmutablearray *moles; int tagcount; int molecount; ccsprite *mallet; cgpoint malletposition; } -(cclayer*) runrecipe; -(void) step; -(void) initbackground; -(void) createmoleatposition:(cgpoint)point withz:(float)z; -(void) processmolehit; -(void) addhiscorestomenu; -(void) loadhiscores; -(void) addhiscore; -(void) deletehiscores; -(void) startnewgame; -(void) gameover; -(void) step:(cctime)delta; -(void) cctouchesbegan:(nsset *)touches withevent:(uievent *)event; @end
which in reunrecipe method calls this:
[self createmoleatposition:ccp(50,205) withz:0];
and call corresponds method:
-(void) createmoleatposition:(cgpoint)point withz:(float)z { ccspriteframecache *cache = [ccspriteframecache sharedspriteframecache]; ccsprite *back = [ccsprite spritewithspriteframe:[cache spriteframebyname:@"mole_back.png"]]; back.position = ccp(point.x, point.y); [self addchild:back z:z tag:tagcount]; tagcount++; mole *mole = [mole spritewithspriteframe:[cache spriteframebyname:@"mole_normal.png"]]; [mole setdownposition:ccp(point.x,point.y-30)]; [self addchild:mole z:z tag:tagcount]; [moles addobject:mole]; nslog(@"moles.count %d", moles.count); tagcount++; ccsprite *front = [ccsprite spritewithspriteframe:[cache spriteframebyname:@"mole_front.png"]]; front.position = ccp(point.x, point.y); [self addchild:front z:z tag:tagcount]; tagcount++; }
the mole class init method looks this:
-(id)init { nslog(@"moleinit"); self = [super init]; if (self != nil) { state = mole_down; ccspriteframecache *cache = [ccspriteframecache sharedspriteframecache]; // //mevpchange //create framenumber array populate ccanimation later nsmutablearray *animationframesarray = [[nsmutablearray alloc] init]; nsmutablearray *animationframesarray2 = [[nsmutablearray alloc] init]; //mevpchange - add frames array [animationframesarray addobject:[cache spriteframebyname:@"mole_normal.png"]]; [animationframesarray2 addobject:[cache spriteframebyname:@"mole_hit.png"]]; normalanim = [[ccanimation alloc] initwithspriteframes:animationframesarray delay:1.0f]; hitanim = [[ccanimation alloc] initwithspriteframes:animationframesarray2 delay:1.0f]; //mevpchange - create animation [animationframesarray release]; [animationframesarray2 release]; // [self runaction:[ccrepeatforever actionwithaction: [ccanimate actionwithanimation:normalanim]]]; } return self; }
now in cocos2d v1.0 code works fine. mole's created , pop , down when whacked. in v2.0, front facing moles nslog in mole init method doesnt called (as evidenced lack of nslog in console).
Comments
Post a Comment