0

我正在尝试用 cocos2d 开发一个 iphone 游戏,我是一个初学者。我在尝试显示屏幕上边界的生命数时遇到了一些问题。所以我想从 3 条生命开始,并在每次错误时减少其中的一条。这是我的代码

-(void)life {
    NSMutableArray *position = [NSMutableArray
                                arrayWithObjects:@"460", @"440", @"420", nil];
    spriteLifeArray = [[NSMutableArray alloc] init];
    for (int i = 0; i<life; i++) {
        spriteLife = [CCSprite spriteWithSpriteFrameName:@"cuore.png"];
        [spriteLife setTag:i];
        spriteLife.scale = 0.5;
        spriteLife.position = ccp([[position objectAtIndex:i] floatValue], 305);
        [self addChild:spriteLife];
        [spriteLifeArray addObject:spriteLife];
    }
}

这是我的游戏结束和生命移除的功能

-(void)gameOver:(int)value punteggio:(id)punti{
    if (value == 1) {
        // partita vinta
    } else if(value == 2) {
        if (life > 1) { // 1
            life = life - 1;
            for (CCSprite *spr in spriteLifeArray) {
                if (life == spr.tag) {
                    [self removeChild:spr cleanup:YES];
                    [self actionBlink];
                }
            }
        } else { 
            //  partita persa
        }
    }
}

资源文件夹中存在一个名为“cuore.png”的文件,但是当我尝试编译时,在启动画面后应用程序崩溃。这是日志:

2013-02-11 19:55:06.635 QuizGame[6672:c07] cocos2d: cocos2d v1.0.1 2013-02-11 19:55:06.636 QuizGame[6672:c07] cocos2d:使用导演类型:CCDirectorDisplayLink 2013-02-11 19:55:06.664 QuizGame[6672:c07] cocos2d: 操作系统版本: 6.1 (0x06010000) 2013-02-11 19:55:06.664 QuizGame[6672:c07] cocos2d: GL_VENDOR: Apple Computer, Inc. 2013-02-11 19:55:06.665 QuizGame[6672:c07] cocos2d: GL_RENDERER: Apple Software Renderer 2013-02-11 19:55:06.666 QuizGame[6672:c07] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 APPLE 2013-02-11 19 :55:06.667 QuizGame[6672:c07] cocos2d: GL_MAX_TEXTURE_SIZE: 4096 2013-02-11 19:55:06.667 QuizGame[6672:c07] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16 2013-02-11 19:5672:6 c07] cocos2d: GL_MAX_SAMPLES: 4 2013-02-11 19:55:06.668 QuizGame[6672:c07] cocos2d: GL 支持 PVRTC: YES 2013-02-11 19:55:06。668 QuizGame[6672:c07] cocos2d:GL 支持 BGRA8888 纹理:YES 2013-02-11 19:55:06.669 QuizGame[6672:c07] cocos2d:GL 支持 NPOT 纹理:YES 2013-02-11 19:55:06.670 QuizGame [6672:c07] cocos2d:GL 支持 discard_framebuffer:是 2013-02-11 19:55:06.670 QuizGame[6672:c07] cocos2d:编译时支持 NPOT:否 2013-02-11 19:55:06.671 QuizGame[6672: c07] cocos2d:在 TextureAtlas 中使用 VBO 支持编译:是 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame [6672:c07] cocos2d:使用分析支持编译:否 2013-02-11 19:55:06.695 QuizGame[6672:c07] cocos2d:CCSpriteFrameCache:未找到帧 'cuore.png' 2013-02-11 19:55: 06.695 问答游戏[6672:c07]是 2013-02-11 19:55:06.669 QuizGame[6672:c07] cocos2d:GL 支持 NPOT 纹理:是 2013-02-11 19:55:06.670 QuizGame[6672:c07] cocos2d:GL 支持 discard_framebuffer:是 2013- 02-11 19:55:06.670 QuizGame[6672:c07] cocos2d:编译时使用 NPOT 支持:否 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:编译时使用 TextureAtlas 中的 VBO 支持:是 2013- 02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672:c07] cocos2d:编译时使用分析支持:否 2013 -02-11 19:55:06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[6672:c07]是 2013-02-11 19:55:06.669 QuizGame[6672:c07] cocos2d:GL 支持 NPOT 纹理:是 2013-02-11 19:55:06.670 QuizGame[6672:c07] cocos2d:GL 支持 discard_framebuffer:是 2013- 02-11 19:55:06.670 QuizGame[6672:c07] cocos2d:编译时使用 NPOT 支持:否 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:编译时使用 TextureAtlas 中的 VBO 支持:是 2013- 02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672:c07] cocos2d:编译时使用分析支持:否 2013 -02-11 19:55:06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[6672:c07]c07] cocos2d: GL 支持discard_framebuffer: YES 2013-02-11 19:55:06.670 QuizGame[6672:c07] cocos2d: 编译时支持NPOT: NO 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d :在 TextureAtlas 中使用 VBO 支持编译:是 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672: c07] cocos2d:使用 Profiling Support 编译:NO 2013-02-11 19:55:06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[ 6672:c07]c07] cocos2d: GL 支持discard_framebuffer: YES 2013-02-11 19:55:06.670 QuizGame[6672:c07] cocos2d: 编译时支持NPOT: NO 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d :在 TextureAtlas 中使用 VBO 支持编译:是 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672: c07] cocos2d:使用 Profiling Support 编译:NO 2013-02-11 19:55:06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[ 6672:c07]06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672:c07] cocos2d:使用分析支持编译:否 2013-02-11 19:55 :06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[6672:c07]06.671 QuizGame[6672:c07] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是 2013-02-11 19:55:06.672 QuizGame[6672:c07] cocos2d:使用分析支持编译:否 2013-02-11 19:55 :06.695 QuizGame[6672:c07] cocos2d: CCSpriteFrameCache: Frame 'cuore.png' not found 2013-02-11 19:55:06.695 QuizGame[6672:c07]* +[CCSprite spriteWithSpriteFrameName:], /Users/alexbava/Desktop/QuizGame/QuizGame/libs/cocos2d/CCSprite.m:110 2013-02-11 19:55:06.696 QuizGame[6672:c07] 中的断言失败终止应用程序由于未捕获的异常'NSInternalInconsistencyException',理由是: '无效spriteFrameName:cuore.png' * *第一掷调用堆栈:(0x2074012 0x1ca4e7e 0x2073e78 0x14e7665 0x6564e 0xc2bd7 0xc3229 0x40261 0xc1c4d 0xc12ec 0x9931af 0x9937a1 0x99494b 0x9a5cb5 0x9a6beb 0x998698 0x2d7cdf9 0x2d7cad0 0x1fe9bf5 0x1fe9962 0x201abb6 0x2019f44 0x2019e1b 0x99417a 0x995ffc 0xc0dcf 0x2665) libc++abi.dylib:终止调用抛出异常 (lldb)

我想我犯了一个愚蠢的错误或遗漏了什么。任何人都可以帮助我吗?

4

2 回答 2

2

您使用的 CCSprite 构造函数将在 CCSpriteFrame 缓存中查找 CCSpriteFrame 对象。如果您只想从名为“cuore.png”的文件中创建精灵,请使用构造函数:

CCSprite * spriteLife = [CCSprite spriteWithFile:@"cuore.png"];

Sprite 帧通常用于动画,或管理包含许多(有时是不相关的)纹理的大型纹理图集。

于 2013-02-11T19:02:28.383 回答
1

spriteWithSpriteFrameName 一般与 CCSpriteFrameCache 一起使用,请使用 'spriteWithFile'。:)

于 2013-02-11T19:04:57.153 回答