I’m trying to develop an iphone game with cocos2d and I’m a beginner.
I have some problems trying to show the number of lives in the upper boundary of the screen. So I want to start with 3 lives and decrease one of them at each error. This is my code
-(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];
}
}
and this is my function for the gameover and the the life removing
-(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
}
}
}
A file named “cuore.png” exists in the Resources Folder, But when I try to compile, after the splashscreen the app crashes. This is the log:
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: Using Director
Type:CCDirectorDisplayLink 2013-02-11 19:55:06.664 QuizGame[6672:c07]
cocos2d: OS version: 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:55:06.667 QuizGame[6672:c07] cocos2d: GL_MAX_SAMPLES:
4 2013-02-11 19:55:06.668 QuizGame[6672:c07] cocos2d: GL supports
PVRTC: YES 2013-02-11 19:55:06.668 QuizGame[6672:c07] cocos2d: GL
supports BGRA8888 textures: YES 2013-02-11 19:55:06.669
QuizGame[6672:c07] cocos2d: GL supports NPOT textures: YES 2013-02-11
19:55:06.670 QuizGame[6672:c07] cocos2d: GL supports
discard_framebuffer: YES 2013-02-11 19:55:06.670 QuizGame[6672:c07]
cocos2d: compiled with NPOT support: NO 2013-02-11 19:55:06.671
QuizGame[6672:c07] cocos2d: compiled with VBO support in TextureAtlas
: YES 2013-02-11 19:55:06.671 QuizGame[6672:c07] cocos2d: compiled
with Affine Matrix transformation in CCNode : YES 2013-02-11
19:55:06.672 QuizGame[6672:c07] cocos2d: compiled with 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] * Assertion failure in +[CCSprite
spriteWithSpriteFrameName:],
/Users/alexbava/Desktop/QuizGame/QuizGame/libs/cocos2d/CCSprite.m:110
2013-02-11 19:55:06.696 QuizGame[6672:c07] Terminating app due to
uncaught exception ‘NSInternalInconsistencyException’, reason:
‘Invalid spriteFrameName: cuore.png’
** First throw call stack: (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: terminate called throwing an exception (lldb)
I think I’ve made a stupid error or something missing. Can anyone help me please?
the CCSprite constructor you took will look for a CCSpriteFrame object in the CCSpriteFrame cache. If you juste wanted to create a sprite from a file named ‘cuore.png’ use the constructor :
Sprite frames are typically used for animations, or managing large texture atlases that contain many (and sometimes unrelated) textures.