2016-07-09 43 views
1

這裏的SKAction的代碼:SpriteKit應用程序崩潰運行時[SKAction moveByX:Y:時間]

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

這裏就是我如何執行SKAction:

[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]; 
} 
+0

您發佈的代碼非常好。不過我不喜歡你如何命名你的序列。這有點令人困惑,因爲下劃線通常表示您正在使用iVars。無論如何,你可以展示你的'spawnPipes:'方法是怎樣的? – Whirlwind

+0

我用spawnPipes方法更新了主文章。 – Ziph0n

+0

所以你在本地使用_movePipesAndRemove變量(在spawnPipes方法中),對吧?但是你有沒有宣佈它是一個場景的屬性? – Whirlwind

回答

0

您應該針對不同的SKNodes新SKActions。

1

我意識到你解決了你的問題,但我認爲這個答案可能對未來某個人有所幫助。一個簡單的方法來獲取您所要執行的操作如下:

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

這是一個很好的方法來做到這一點!謝謝!我會記住這一點 – Ziph0n

相關問題