Ios 运行[SKAction moveByX:y:duration]时SpriteKit应用程序崩溃

Ios 运行[SKAction moveByX:y:duration]时SpriteKit应用程序崩溃,ios,objective-c,sprite-kit,skaction,Ios,Objective C,Sprite Kit,Skaction,以下是SKAction的代码: SKAction *movePipes = [SKAction moveByX:x y:y duration:d]; SKAction *removePipes = [SKAction removeFromParent]; SKAction *_movePipesAndRemove = [SKAction sequence:@[movePipes, removePipes]]; [object runAction:_movePipesAndRemove]; 下

以下是SKAction的代码:

SKAction *movePipes = [SKAction moveByX:x y:y duration:d];
SKAction *removePipes = [SKAction removeFromParent];
SKAction *_movePipesAndRemove = [SKAction sequence:@[movePipes, removePipes]];
[object runAction:_movePipesAndRemove];
下面是我执行SKAction的方式:

SKAction *movePipes = [SKAction moveByX:x y:y duration:d];
SKAction *removePipes = [SKAction removeFromParent];
SKAction *_movePipesAndRemove = [SKAction sequence:@[movePipes, removePipes]];
[object runAction:_movePipesAndRemove];
我检查了三倍,我确定错误来自这里

下面是崩溃日志:

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
更新:

根据@Whirlwind的要求,以下是整个spawnPipes方法:

-(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];
}

您应该为不同的SKNodes创建新的SKActions。

我知道您解决了您的问题,但我认为这个答案可能对将来的人有所帮助。获得您所追求的行动的简单方法如下:

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

你发布的代码非常好。我还是不喜欢你给序列命名的方式。这有点令人困惑,因为下划线通常是您正在使用IVAR的指示器。无论如何,你能展示一下你的
spawnPipes:
方法是什么样子吗?我用spawnPipes方法更新了主帖。所以你使用了_movepipes和remove variable local(在spawnPipes方法内部),对吗?但您是否已将其声明为场景的属性?您应该这样做:1)声明SKAction类型的属性,2)在init或didMoveToView方法内部初始化此变量。3) 在spawnPipes方法中重复使用它。好的,没问题。事实上,我什么也没做:)但很高兴听到你明白了。这是一个很好的方法!谢谢我会记住的