Я использую NSMutableArray
, определенный в подклассе CCLayer
следующим образом:
//
// GameOverScene.h
// Cocos2DSimpleGame
//
// Created by Ray Wenderlich on 2/10/10.
// Copyright 2010 Ray Wenderlich. All rights reserved.
//
#import "cocos2d.h"
@interface scoLayer : CCColorLayer {
CCLabelTTF *_label;
CCLabelTTF *_howtoplay;
NSMutableArray *highscores;
}
@property (nonatomic, retain) CCLabelTTF *label;
@property (nonatomic, retain) NSMutableArray *highscores;
@property (nonatomic, retain) CCLabelTTF *back;
+ (id)initWithScore:(int)lastScore;
+(void)print_label:(int)lb;
+(void)menu;
@end
@interface sco : CCScene {
scoLayer *_layer;
}
@property (nonatomic, retain) scoLayer *layer;
@end
Вот файл .m для класса:
@implementation sco
@synthesize layer = _layer;
- (id)init {
if ((self = [super init])) {
self.layer = [scoLayer node];
[self addChild:_layer];
}
return self;
}
- (void)dealloc {
[_layer release];
_layer = nil;
[super dealloc];
}
@end
@implementation scoLayer
@synthesize label = _label;
@synthesize highscores ;
//@synthesize how_to_play ;
@synthesize back;
-(id) init
{
if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
self.label = [CCLabelTTF labelWithString:@"" fontName:@"Arial" fontSize:16];
//self.how_to_play = [CCLabelTTF labelWithString:@"" fontName:@"Arial" fontSize:32];
self.highscores = [[NSMutableArray alloc] initWithObjects:nil ];
// [highscores addObject:@"asdf"];
// NSLog(@"hig %@", [highscores objectAtIndex:0]);
_label.color = ccc3(0,0,0);
_label.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:_label z:100];
[self runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:3],
[CCCallFunc actionWithTarget:self selector:@selector(gameOverDone)],
nil]];
CCSprite *bk1 =[CCSprite spriteWithFile:@"bg3.png" ];//rect: CGRectMake(0, 0, 40, 480)];
[bk1 setPosition:ccp(160, 239)];
[self addChild:bk1 z:0];
CCMenuItem *back = [CCMenuItemImage
itemFromNormalImage:@"gameBackButton.png" selectedImage:@"gameBackButton.png"
target:self selector:@selector(back_game:)];
CCMenu *menu1 = [CCMenu menuWithItems:back,nil];
menu1.position = ccp(70, 100);
[menu1 alignItemsVerticallyWithPadding: 40.0f];
// [self addChild:menu z: 2];
[self addChild:menu1 z: 0];
}
return self;
}
В этомфункция:
+(id)initWithScore:(int)lastScore
{
NSLog(@"score %d", lastScore);
//NSMutableArray *highscores = [[NSMutableArray alloc] initWithObjects:nil ];
//[highscores addObject:@"asdf"];
if([highscores count] == 0)
}
Я хочу использовать массив highscores
и вставить данные (lastScore
), но когда я делаю это, приложение завершается с сигналом EXC_BAD_ACCESS
.Как я могу исправить эту ошибку?