Моя проблема в том, что некоторые слои оказываются освобожденными. Мой предварительный просмотр был убежден, что [CCDirector sharedDirector] replaceScene: [Узел меню]]; или подобное делает все для меня. На заднем плане остаются активные слои, если я загружаю новый слой. Это приводит к странным ошибкам. Во всяком случае, код внизу имеет счет сохранения 2 во время вызова onExit. Dealloc никогда не называется. Удаление rootVC решает проблему. К сожалению, мне это нужно.
#import "Help.h"
#import "Constants.h"
#import "MainMenu.h"
@implementation Help
-(void)showText:(ccTime)dt
{
[self unschedule:_cmd];
txt.hidden = NO;
}
-(void)onExit
{
CCLOG(@"retain count %i", [self retainCount]);
[super onExit];
}
-(id) init
{
if ( (self = [super init]) )
{
NSString* bgPath;
NSString* button2Path;
NSString* button2PressPath;
CGRect textFrame;
int fontsize;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
bgPath = @"background-ipad.png";
button2Path = @"button2-ipad.png";
button2PressPath = @"button2_press-ipad.png";
textFrame = CGRectMake(60, 140, 920, 500);
fontsize = 24;
} else {
bgPath = @"background.png";
button2Path = @"button2.png";
button2PressPath = @"button2_press.png";
textFrame = CGRectMake(10, 45, 460, 217);
fontsize = [kMenuFontSize intValue];
}
NSString* helpText = NSLocalizedString(@"Bla bla bla yada yada yada", @"Helptext");
rootVC = [UIApplication sharedApplication].keyWindow.rootViewController; // +1 retain to the layer
txt = [[[UITextView alloc] initWithFrame:textFrame] autorelease];
txt.text = helpText;
[txt setEditable:NO];
[txt setFont:[UIFont fontWithName:@"Sui Generis" size:fontsize]];
[txt setTextColor:[UIColor whiteColor]];
[txt setBackgroundColor:[UIColor clearColor]];
[rootVC.view addSubview:txt];
txt.hidden = YES;
[self schedule:@selector(showText:) interval:1];
self.isTouchEnabled = NO;
CGSize ss = [[CCDirector sharedDirector] winSize];
CCSprite* background = [CCSprite spriteWithFile:bgPath];
background.position = ccp(ss.width*0.5, ss.height*0.5);
[self addChild:background z:0];
CCLabelTTF* backLabel = [CCLabelTTF labelWithString:NSLocalizedString(@"Back", @"back button at help") fontName:kMenuFont fontSize:fontsize];
backLabel.position = ccp(ss.width * 0.1, ss.height * 0.1);
[backLabel setColor:ccBLACK];
[self addChild:backLabel z:20];
CCMenuItemImage* backButton = [CCMenuItemImage itemFromNormalImage:button2Path selectedImage:button2PressPath block:^(id sender) {
[txt removeFromSuperview];
id trans = [CCTransitionFade transitionWithDuration:1 scene:[MainMenu node]];
[[CCDirector sharedDirector] replaceScene:trans];
} ];
backButton.position = ccp(ss.width * 0.1, ss.height * 0.1);
CCMenu* menu = [CCMenu menuWithItems:backButton, nil];
[menu setPosition:ccp(0,0)];
[self addChild:menu z:10];
}
return self;
}
-(void)dealloc
{
CCLOG(@"Help dealloc");
[super dealloc];
}
@end