简体   繁体   中英

EXEC_BAD_ACCESS on SKAction

I'm developing a Spritekit game.

I recevie an EXEC_BAD_ACCESS exception when touchind a node i try to run an action

This function catches the touch

    -(void)selectNodeForTouch:(CGPoint)location {
    SKNode *touchedNode = (SKNode *)[self nodeAtPoint:location];
    NSLog(@"touched : %@",touchedNode.name);

    if([[touchedNode name] isEqualToString:@"piece"]){
        Piece *piece = (Piece *)[self nodeAtPoint:location];
        if ([piece isRotated])
            [piece rotateToFront];
        else
            [piece rotateToBack];
    }
}

The object Piece Method rotateBack :

    -(void)rotateToBack{
    SKAction *rotationToBack = [SKAction animateWithTextures:[self animationFrames] timePerFrame:0.11];
    [self runAction:rotationToBack withKey:@"rotation-to-back"];
    [self setRotated:YES];
};

[self animationFrames] is a NSMutable array converted into NSArray with

[self setAnimationFrames:[NSArray arrayWithArray:frames]];

Finally frames is an the NSMutableArray containing some SKTextures

The executions brokes on animation execution.

In the Piece class

Change this line:

NSString *imageName = [NSString stringWithFormat:@"%@-1%@",[self baseImageName],imageResolution];

to

NSString *imageName = [NSString stringWithFormat:@"%@-1",[self baseImageName]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM