简体   繁体   中英

SpriteKit app crash when running [SKAction moveByX:y:duration]

Here's the code of the SKAction:

SKAction *movePipes = [SKAction moveByX:x y:y duration:d];
SKAction *removePipes = [SKAction removeFromParent];
SKAction *_movePipesAndRemove = [SKAction sequence:@[movePipes, removePipes]];

And here's how I execute the SKAction:

[object runAction:_movePipesAndRemove];

I tripled checked, I'm certain that the error come from here.

Here's the crashlog:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0       libobjc.A.dylib                 0x1996d00b0 0x1996b0000 + 0x200b0   // objc_retain + 0x10
1       SpriteKit                       0x18a08aa24 0x18a030000 + 0x5aa24   // -[SKNode runAction:] + 0x1c
2     + FlappyGo.dylib                  0x1027c61c0 0x1027bc000 + 0xa1c0    // -[MyScene spawnPipes] + 0x764
3       SpriteKit                       0x18a0b8458 0x18a030000 + 0x88458   // -[SKPerformSelector updateWithTarget:forTime:] + 0x58
4       SpriteKit                       0x18a056b64 0x18a030000 + 0x26b64   // SKCSequence::cpp_updateWithTargetForTime(SKCNode*, double) + 0x64
5       SpriteKit                       0x18a047588 0x18a030000 + 0x17588   // SKCRepeat::cpp_updateWithTargetForTime(SKCNode*, double) + 0x40
6       SpriteKit                       0x18a04cff0 0x18a030000 + 0x1cff0   // SKCNode::update(double, float) + 0xe4
7       SpriteKit                       0x18a05d1c0 0x18a030000 + 0x2d1c0   // -[SKScene _update:] + 0x150
8       SpriteKit                       0x18a07974c 0x18a030000 + 0x4974c   // -[SKView _update:] + 0x328
9       SpriteKit                       0x18a07689c 0x18a030000 + 0x4689c   // __59-[SKView _renderSynchronouslyForTime:preRender:postRender:]_block_invoke + 0xa4
10      SpriteKit                       0x18a076770 0x18a030000 + 0x46770   // -[SKView _renderSynchronouslyForTime:preRender:postRender:] + 0xd4
11      SpriteKit                       0x18a079290 0x18a030000 + 0x49290   // -[SKView layoutSubviews] + 0x60
12      UIKit                           0x18a20aff0 0x18a1fc000 + 0xeff0    // -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 0x284
13      QuartzCore                      0x189a11f14 0x189a04000 + 0xdf14    // -[CALayer layoutSublayers] + 0x94
14      QuartzCore                      0x189a0cb20 0x189a04000 + 0x8b20    // CA::Layer::layout_if_needed(CA::Transaction*) + 0x124
15      QuartzCore                      0x189a0c9e0 0x189a04000 + 0x89e0    // CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 0x20
16      QuartzCore                      0x189a0c07c 0x189a04000 + 0x807c    // CA::Context::commit_transaction(CA::Transaction*) + 0xfc
17      QuartzCore                      0x189a0bdd0 0x189a04000 + 0x7dd0    // CA::Transaction::commit() + 0x204
18      UIKit                           0x18a20e0c0 0x18a1fc000 + 0x120c0   // _UIApplicationHandleEventQueue + 0x16a8
19      CoreFoundation                  0x184c705a4 0x184b94000 + 0xdc5a4   // __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 0x18
20      CoreFoundation                  0x184c70038 0x184b94000 + 0xdc038   // __CFRunLoopDoSources0 + 0x21c
21      CoreFoundation                  0x184c6dd38 0x184b94000 + 0xd9d38   // __CFRunLoopRun + 0x2d4
22      CoreFoundation                  0x184b9cdc0 0x184b94000 + 0x8dc0    // CFRunLoopRunSpecific + 0x180
23      GraphicsServices                0x18fb30088 0x18fb24000 + 0xc088    // GSEventRunModal + 0xb4
24      UIKit                           0x18a276f44 0x18a1fc000 + 0x7af44   // UIApplicationMain + 0xcc
25      pokemongo (*)                   0x10000c8cc 0x100008000 + 0x48cc    // 0x00004830 + 0x9c
26      libdyld.dylib                   0x199ed68b8 0x199ed4000 + 0x28b8    // start + 0x4

Update:

As requested by @Whirlwind, here's the entire spawnPipes method:

-(void)spawnPipes {

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    SKNode* pipePair = [SKNode node];
    pipePair.position = CGPointMake( screenWidth + 30, 0 );
    pipePair.zPosition = -10;

    CGFloat y = arc4random() % (NSInteger)( screenHeight / 3 );

    SKSpriteNode* firstPipe;
    firstPipe = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/FlappyGo/firstpipe.png"]]];
    [firstPipe setScale:2];
    firstPipe.position = CGPointMake( 0, y );
    firstPipe.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:firstPipe.size];
    firstPipe.physicsBody.dynamic = NO;
    firstPipe.physicsBody.categoryBitMask = pipeCategory;
    firstPipe.physicsBody.contactTestBitMask = birdCategory;

    [pipePair addChild:firstPipe];

    SKSpriteNode* secondPipe;
    secondPipe = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/FlappyGo/secondPipe.png"]]];
    [secondPipe setScale:2];
    secondPipe.position = CGPointMake( 0, y + firstPipe.size.height + 100 );
    secondPipe.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:secondPipe.size];
    secondPipe.physicsBody.dynamic = NO;
    secondPipe.physicsBody.categoryBitMask = pipeCategory;
    secondPipe.physicsBody.contactTestBitMask = birdCategory;
    [pipePair addChild:secondPipe];

    SKNode* contactNode = [SKNode node];
    contactNode.position = CGPointMake( firstPipe.size.width + _bird.size.width / 2, CGRectGetMidY( self.frame ) );
    contactNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(secondPipe.size.width, self.frame.size.height)];
    contactNode.physicsBody.dynamic = NO;
    contactNode.physicsBody.categoryBitMask = scoreCategory;
    contactNode.physicsBody.contactTestBitMask = birdCategory;
    [pipePair addChild:contactNode];

    [pipePair runAction:_movePipesAndRemove];

    [_pipes addChild:pipePair];
}

I realize you solved your problem, but I thought this answer could be helpful for someone in the future. A simple way to get the action you're after is like this:

[object runAction:movePipes completion:^{
   [object removeFromParent];
}];

您应该为不同的 SKNode 创建新的 SKAction。

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