Cocos2d iphone Cocos2D-[CCSpriteFrame delayUnits]:发送到实例的无法识别的选择器

Cocos2d iphone Cocos2D-[CCSpriteFrame delayUnits]:发送到实例的无法识别的选择器,cocos2d-iphone,Cocos2d Iphone,我遵循了联机指南(),但我的应用程序在运行时崩溃,出现以下错误: 2013-02-19 16:03:23.028 WhackAMole[3616:907] -[CCSpriteFrame delayUnits]: unrecognized selector sent to instance 0x1f548ce0 如果添加异常断点,Xcode将暂停此函数(Cocos2D)中的代码执行: 顺便说一下,这是代码: #import "GameScene.h" @implementation Game

我遵循了联机指南(),但我的应用程序在运行时崩溃,出现以下错误:

2013-02-19 16:03:23.028 WhackAMole[3616:907] -[CCSpriteFrame
delayUnits]: unrecognized selector sent to instance 0x1f548ce0
如果添加异常断点,Xcode将暂停此函数(Cocos2D)中的代码执行:

顺便说一下,这是代码:

#import "GameScene.h"

@implementation GameScene

+ (id)scene
{
    // the usual ... create the scene and add our layer straight to it
    CCScene *scene = [CCScene node];
    CCLayer* layer = [GameScene node];
    [scene addChild:layer];
    return scene;
}

#pragma mark - Life Cycle

- (id)init
{
    // Determine names of sprite sheets and plists to load
    NSString *bgSheet = @"background.pvr.ccz";
    NSString *bgPlist = @"background.plist";
    NSString *fgSheet = @"foreground.pvr.ccz";
    NSString *fgPlist = @"foreground.plist";
    NSString *sSheet = @"sprites.pvr.ccz";
    NSString *sPlist = @"sprites.plist";
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        bgSheet = @"background-hd.pvr.ccz";
        bgPlist = @"background-hd.plist";
        fgSheet = @"foreground-hd.pvr.ccz";
        fgPlist = @"foreground-hd.plist";
        sSheet = @"sprites-hd.pvr.ccz";
        sPlist = @"sprites-hd.plist";
    }

    if ((self = [super init]))
    {
        [self setScreenSaverEnabled:NO];     

        // Load background and foreground
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:bgPlist];
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:fgPlist];

        // Add background
        CGSize winSize = [CCDirector sharedDirector].winSize;
        CCSprite *dirt = [CCSprite spriteWithSpriteFrameName:@"bg_dirt.png"];
        dirt.scale = 2.0;
        dirt.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:dirt z:-2];

        // Add foreground
        CCSprite *lower = [CCSprite spriteWithSpriteFrameName:@"grass_lower.png"];
        lower.anchorPoint = ccp(0.5, 1);
        lower.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:lower z:1];

        CCSprite *upper = [CCSprite spriteWithSpriteFrameName:@"grass_upper.png"];
        upper.anchorPoint = ccp(0.5, 0);
        upper.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:upper z:-1];

        CCSpriteBatchNode *spriteNode = [CCSpriteBatchNode batchNodeWithFile:sSheet];
        [self addChild:spriteNode z:0];
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:sPlist];

        moles = [[NSMutableArray alloc] init];

        CCSprite *mole1 = [CCSprite spriteWithSpriteFrameName:@"mole_1.png"];
        mole1.position = CGPointMake(85, 85);
        [spriteNode addChild:mole1];
        [moles addObject:mole1];

        CCSprite *mole2 = [CCSprite spriteWithSpriteFrameName:@"mole_1.png"];
        mole2.position = CGPointMake(240, 85);
        [spriteNode addChild:mole2];
        [moles addObject:mole2];

        CCSprite *mole3 = [CCSprite spriteWithSpriteFrameName:@"mole_1.png"];
        mole3.position = CGPointMake(395, 85);
        [spriteNode addChild:mole3];
        [moles addObject:mole3];

        [self schedule:@selector(tryPopMoles:) interval:0.5];

        laughAnim = [self animationFromPlist:@"laughAnim" delay:0.1];
        hitAnim = [self animationFromPlist:@"hitAnim" delay:0.02];
        [[CCAnimationCache sharedAnimationCache] addAnimation:laughAnim name:@"laughAnim"];
        [[CCAnimationCache sharedAnimationCache] addAnimation:hitAnim name:@"hitAnim"];
    }

    return self;
}

-(void) dealloc
{
    [moles release];
    moles = nil;

    [super dealloc];
}

#pragma mark - Mole Managment

- (void)tryPopMoles:(ccTime)dt
{
    for (CCSprite *mole in moles)
    {
        if (arc4random() % 3 == 0)
        {
            if (mole.numberOfRunningActions == 0)
            {
                [self popMole:mole];
            }
        }
    }
}

- (void) popMole:(CCSprite *)mole
{
    CCMoveBy *moveUp = [CCMoveBy actionWithDuration:0.2 position:CGPointMake(0, mole.contentSize.height)];
    CCEaseInOut *easeMoveUp = [CCEaseInOut actionWithAction:moveUp rate:3.0];
    CCAction *easeMoveDown = [easeMoveUp reverse];
    CCAnimate *laugh = [CCAnimate actionWithAnimation:laughAnim];
    laughAnim.restoreOriginalFrame = YES;

    [mole runAction:[CCSequence actions:easeMoveUp, laugh, easeMoveDown, nil]];
}

- (CCAnimation *)animationFromPlist:(NSString *)animPlist delay:(float)delay
{

    //NSString *plistPath = [[NSBundle mainBundle] pathForResource:animPlist ofType:@"plist"];
    //NSArray *animImages = [NSArray arrayWithContentsOfFile:plistPath];
    NSMutableArray *animFrames = [NSMutableArray array];
    /*
    for(NSString *animImage in animImages)
    {        
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:animImage]];
    }
    */

    if ([animPlist isEqual: @"hitAnim"])
    {
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump1.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump4.png"]];

        return [CCAnimation animationWithAnimationFrames:animFrames delayPerUnit:delay loops:6];
    }

    else
    {
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh1.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh1.png"]];

        return [CCAnimation animationWithAnimationFrames:animFrames delayPerUnit:delay loops:6];
    }
}

#pragma mark - Misc

-(void) setScreenSaverEnabled:(bool)enabled
{
    UIApplication *thisApp = [UIApplication sharedApplication];
    thisApp.idleTimerDisabled = !enabled;
}

@end
有人能帮我吗

先谢谢你

已解决

而不是使用:
return[cAnimation animationWithAnimationFrames:AnimationFrames delayPerUnit:delay loops:6]

    NSMutableArray *animFrames = [NSMutableArray array];

    if ([animPlist isEqual: @"hitAnim"])
    {
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump1.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_thump4.png"]];

        return [CCAnimation animationWithAnimationFrames:animFrames delayPerUnit:delay loops:6];
    }

    else
    {
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh1.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh2.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh3.png"]];
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mole_laugh1.png"]];

        return [CCAnimation animationWithAnimationFrames:animFrames delayPerUnit:delay loops:6];
    }
我决定使用:
[cAnimation animation with priteframes:animFrames delay:delay]

NSString *plistPath = [[NSBundle mainBundle] pathForResource:animPlist ofType:@"plist"];
    NSArray *animImages = [NSArray arrayWithContentsOfFile:plistPath];
    NSMutableArray *animFrames = [NSMutableArray array];

    for(NSString *animImage in animImages)
    {        
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:animImage]];
    }

    return [CCAnimation animationWithSpriteFrames:animFrames delay:delay]; //Here's the
                                                                           //main
                                                                           //difference

arrayOfAnimationFrames
至少包含一个
CCSpriteFrame
对象,但它应该只包含
CCAnimationFrame
对象


由于您没有显示填充
arrayOfAnimationFrames
的代码,因此我无法说明为什么会发生这种情况,但您肯定应该查看该代码。这可能很简单,因为在调用
addObject

时意外使用了错误的变量。我在函数中填充了ArrayFanImationFrames:-(cAnimation*)animationFromPlist:(NSString*))Animaplist delay:(float)delay,并在init方法中“调用”了它。您能修改我的代码吗?我不明白怎么了。
NSString *plistPath = [[NSBundle mainBundle] pathForResource:animPlist ofType:@"plist"];
    NSArray *animImages = [NSArray arrayWithContentsOfFile:plistPath];
    NSMutableArray *animFrames = [NSMutableArray array];

    for(NSString *animImage in animImages)
    {        
        [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:animImage]];
    }

    return [CCAnimation animationWithSpriteFrames:animFrames delay:delay]; //Here's the
                                                                           //main
                                                                           //difference