2016-07-09 4 views
1

다음은 SKAction의 코드입니다 :SpriteKit 응용 프로그램의 충돌 [SKAction moveByX : 예 : 지속 시간]

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

을 그리고 여기가 SKAction 실행 방법은 다음과 같습니다, 내가 확인 3 배

[object runAction:_movePipesAndRemove]; 

를 I 그 실수가 여기에서 오는 것이 확실합니다.

다음은 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 

업데이트 :

@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

그래서 spawnPipes 메소드 내부에서 _movePipesAndRemove 변수를 로컬로 사용하고 있습니다. 맞습니까? 하지만 장면의 속성으로 선언하셨습니까? – Whirlwind

답변

0

당신은 다른 SKNodes 새로운 SKActions을 만들어야합니다.

1

나는 당신이 당신의 문제를 해결했다는 것을 깨달았지만이 대답은 미래의 누군가에게 도움이 될 수 있다고 생각했습니다. 간단한 행동을 취하는 방법은 다음과 같습니다.

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

그걸 할 수있는 좋은 방법입니다! 감사! 나는 그것을 염두에 두겠다. – Ziph0n

관련 문제