0

我有这个类:

//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

在其 reunRecipe 方法中调用它:

[self createMoleAtPosition:ccp(50,205) withZ:0];

并且该调用对应于此方法:

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

}

Mole 类的 init 方法如下所示:

-(id)init {
    NSLog(@"moleinit");

    self = [super init];
    if (self != nil) {
        state = MOLE_DOWN;

        CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];

        //
        //MEVPCHANGE
        //Create framenumber array to populate ccanimation later
        NSMutableArray *animationFramesArray = [[NSMutableArray alloc] init];
        NSMutableArray *animationFramesArray2 = [[NSMutableArray alloc] init];

        //MEVPCHANGE - add frames to 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;
}

现在在 cocos2d v1.0 中,这段代码可以正常工作。鼹鼠被创造出来,当它们被击打时它们会上下跳动。但是在 v2.0 中,我只得到了正面的痣,但 Mole init 方法中的 NSLog 甚至没有被调用(控制台中缺少 NSLog 就证明了这一点)。

4

0 回答 0