无法弄清楚这些错误:

时间:2014-09-05 08:05:16

标签: ios iphone xcode sprite-kit

我正在开发一款游戏,我在故事板上添加了一个菜单后就开始了这个,即使删除它之后,我也会收到此错误:

2014-09-05 19:55:22.155 hygvhgvbv[2875:60b] Cannot find executable for CFBundle 0x998cb40 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
hygvhgvbv(2875,0x20581a8) malloc: 
*** mach_vm_map(size=8388608) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc

这是我的代码: Myscene.h

#import <SpriteKit/SpriteKit.h>

@interface MyScene : SKScene
@property (strong, nonatomic) SKLabelNode *scoreLabel;
@property (nonatomic) NSInteger score;
@property (nonatomic) BOOL gameOver;
@property SKEmitterNode *shatter;

typedef NS_ENUM(NSInteger, SpriteType) {
    SpriteTypeBackground,
    SpriteTypeSquare
};

Myscene.m

    #import "MyScene.h"

@interface MyScene()

@property SKSpriteNode *background;
@property SKSpriteNode *square;

@end

@implementation MyScene
#define kNumberOfColors     2 //Setting total number of possible colors



-(id)initWithSize:(CGSize)size {

    if (self = [super initWithSize:size]) {
        /* Setup your scene here */
        [self runAction:[SKAction repeatActionForever: [SKAction sequence:@[[SKAction                                                                             performSelector:@selector(addSquareAndBackground) onTarget:self] ]]]];

        //Score Label
        float margin = 10;
        self.scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
        self.scoreLabel.text = @"Score: 0";
        self.scoreLabel.fontSize = [self convertFontSize:14];
        self.scoreLabel.zPosition = 4;
        self.scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;
        self.scoreLabel.position = CGPointMake(margin, margin);
        [self addChild:self.scoreLabel];



    }
    return self;
}

- (float)convertFontSize:(float)fontSize
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return fontSize * 2;
    } else {
        return fontSize;
    }
}


-(void)addSquareAndBackground {
    _background = [self createSpriteWithType:SpriteTypeBackground];
    _square = [self createSpriteWithType:SpriteTypeSquare];
}

-(void)removeSquareAndBackground {
    [_background removeFromParent];
    [_square removeFromParent];
}

-(SKSpriteNode *) createSpriteWithType:(SpriteType)type {
    // Select a color randomly
    NSString *colorName = [self randomColorName];
    SKSpriteNode *sprite;
    if (type == SpriteTypeBackground) {
        NSString *name = [NSString stringWithFormat:@"%@Outline",colorName];
        sprite = [SKSpriteNode spriteNodeWithImageNamed:name];
        sprite.name = name;
        sprite.size = CGSizeMake(CGRectGetHeight(self.frame), CGRectGetWidth(self.frame));
    }
    else {
        sprite = [SKSpriteNode spriteNodeWithImageNamed:colorName];
        sprite.name = [NSString stringWithFormat:@"%@Sprite",colorName];
        sprite.size = CGSizeMake(50, 50);
    }
    sprite.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
    [self addChild:sprite];

    return sprite;
}

- (NSString *) randomColorName {
    NSString *colorName;
    switch (arc4random_uniform(kNumberOfColors)) {
        case 0:
            colorName = @"blue";
            break;
        case 1:
            colorName = @"pink";
            break;
            // Add more colors here
        default:
            break;
    }
    return colorName;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];

    NSString *pinkShatterPath = [[NSBundle mainBundle] pathForResource:@"pinkShatter" ofType:@"sks"];
    SKEmitterNode *pinkShatter = [NSKeyedUnarchiver unarchiveObjectWithFile:pinkShatterPath];
    pinkShatter.particlePosition = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));


    if (node == _square) {
        // Extract the color name from the node name
        NSArray *squareNameParts = [node.name componentsSeparatedByCharactersInSet:[NSCharacterSet uppercaseLetterCharacterSet]];
        // Extract the color name from the node name
        NSArray *backgroundNameParts = [_background.name componentsSeparatedByCharactersInSet:[NSCharacterSet uppercaseLetterCharacterSet]];
        // Compare if the colors match
        if ([backgroundNameParts[0] isEqualToString: squareNameParts[0]]) {
            //Add SKAction to add 1 to score label
            [SKAction performSelector:@selector(removeSquareAndBackground) onTarget:self];
            [self addChild:pinkShatter];
            self.score += 10;

            //NSLog(@"Score"); for console error detection
        } else {
            //NSLog(@"Lost"); //Add SKAction to display game-over menu
            SKLabelNode *gameOverLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
            gameOverLabel.text = @"You Lose!!!!!";
            gameOverLabel.fontSize = 20;
            gameOverLabel.zPosition = 4;
            gameOverLabel.position = CGPointMake(CGRectGetMidX(self.frame),
                                                 CGRectGetMidY(self.frame));

            [gameOverLabel setScale:0.1];

            [self addChild:gameOverLabel];
            [gameOverLabel runAction:[SKAction scaleTo:1.0 duration:0.5]];

            self.gameOver = YES;
            return;
        }
    }


}

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
    [self.scoreLabel setText:[NSString stringWithFormat:@"Score: %ld", (long)self.score]];
}

@end

我无法弄清楚如何解决这些错误。

0 个答案:

没有答案