0

所以我想用 pushscene/popscene 做一个升级屏幕。当它是一个空白场景时,pushscene 有效,但当它是我想要的场景时则无效。我的场景/图层完全加载,所有图像和文本都显示了它们完全正确的内容。在所有图像加载后,有一个 EXC BAD ACCESS 似乎没有链接到正在发送的任何特定消息。任何帮助或进一步的诊断测试将不胜感激。

我有一个版本,我注释掉了精灵和标签,但它仍然崩溃。我有什么大不了的吗?

编辑:我添加了[self = [super init]]and[super onEnter]方法,但仍然存在同样的问题。这是另一回事。有任何想法吗?

编辑编辑:我认为这与我正在使用的 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

`

4

2 回答 2

1

我没有看到任何[super onEnter];类似[super init]的东西......那是你的问题

首先[super onEnter]onEnter.

其次添加一个像这样的init方法:

-(id)init{
if (self=[super init]){}
}

在方法[super onExit]末尾添加第三个onExit

于 2012-12-01T00:06:45.247 回答
0

我想通了,这与我发布的代码无关,对此感到抱歉。这只是对非保留数组的愚蠢发布调用。之前保留了阵列,它工作正常。抱歉哭狼

于 2012-12-01T20:15:37.783 回答