所以我试图用pushscene / popscene做一个levelup屏幕。 pushscene在它是一个空白场景时工作,但不是在我想要的场景时。我的场景/图层完全加载所有图像和文本显示其完全正确的内容。加载完所有图像后,会出现一个EXC BAD ACCESS,它似乎与正在发送的任何特定消息无关。任何帮助或进一步的诊断测试将不胜感激。
我有一个版本,我注释了精灵和标签,它仍然崩溃。我有什么大不了的东西吗?
编辑:我添加了[self = [super init]]
和[super onEnter]
方法,但问题仍然存在。这是另一回事。有任何想法吗?
EDITEDIT:我认为这与我正在使用的optionsArray有关,不确定需要保留哪些对象。该数组是CCArray,包含不同容量的NSDictionaries
#import "LevelupLayer.h"
#import "GameManager.h"
@implementation LevelupLayer
@synthesize optionsArray,spritesArray;
@synthesize confirmLabel;
@synthesize counter;
+(id) scene {
CCScene *scene = [CCScene node];
CCLayer* layer = [LevelupLayer node];
[scene addChild:layer];
return scene;
}
-(void)onEnter
{
counter = 1; // for debugging
//Detemine what levelups are possible
GameManager* gm = [GameManager sharedManager]; //GameManager is a helper that oversees communication between layers and plists
optionsArray = [gm possibleLevelups]; //Access plist and formats data into expected format
[optionsArray retain];
int numPossibilities = [optionsArray count];
//Build Levelup layer based on possible options
CGSize size = [[CCDirector sharedDirector] winSize];
//float positionIncrement = (size.width / numPossibilities) - ((size.width/numPossibilities) * 0.5);
float positionIncrement = (size.width / numPossibilities);
float stripWidth = size.width / numPossibilities;
for (int i = 0; i < numPossibilities; i++) {
int slot = i+1;
NSDictionary* optionDict = [optionsArray objectAtIndex:i];
NSString* name = [optionDict objectForKey:@"name"];
NSString* title = [optionDict objectForKey:@"title"];
NSString* description = [optionDict objectForKey:@"description"];
// Add the sprite
CCSprite* optionSpite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@.png",name]];
[self addChild:optionSpite];
[spritesArray addObject: optionSpite];
optionSpite.position = CGPointMake(slot * positionIncrement, size.height*0.60);
[optionSpite setAnchorPoint:CGPointMake(0.5f, 0.5f)];
// Add the description
CCLabelBMFont *optionDescription = [CCLabelBMFont labelWithString:description fntFile:@"bodyFont.fnt" width:stripWidth alignment:kCCTextAlignmentCenter];
[self addChild:optionDescription];
optionDescription.position = CGPointMake(slot * positionIncrement, size.height*0.30);
[optionDescription setAnchorPoint:CGPointMake(0.5f, 0.5f)];
// Add the title
CCLabelBMFont *optionTitle = [CCLabelBMFont labelWithString:title fntFile:@"titleFont.fnt" width:stripWidth alignment:kCCTextAlignmentCenter];
[self addChild:optionTitle];
optionTitle.position = CGPointMake(slot * positionIncrement, size.height*0.90);
[optionTitle setAnchorPoint:CGPointMake(0.5f, 0.5f)];
}
[self scheduleUpdate]; //Update only prints counter to see how many frames it lasts
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
-(void) update:(ccTime)delta
{
CCLOG(@"counter: %d",counter);
counter++;
}
-(void) onExit
{
[optionsArray release];
}
@end
`
答案 0 :(得分:1)
我没有看到任何[super onEnter];
或[super init]
或类似的东西......这是你的问题
首先在[super onEnter]
的第一行添加onEnter
。
第二次添加这样的init方法:
-(id)init{
if (self=[super init]){}
}
第三次在[super onExit]
方法
onExit
答案 1 :(得分:0)
我弄清楚了,这与我发布的代码无关,所以很抱歉。这只是对非保留数组的愚蠢释放调用。以前保留了阵列,它工作正常。抱歉哭狼