【发布时间】:2015-09-08 00:11:28
【问题描述】:
我正在开发一个精灵套件游戏,其中我有一个名为 playCountdown 的动作:
SKAction *playCountdown = [SKAction performSelector:@selector(startCountdown) onTarget:self];
playCountdown 工作正常,但是当它完成时,完成块永远不会被调用。
[self runAction:playCountdown completion:^{
NSLog(@"anything goes");
}];
为了完整性,这里是 startCountdown:
- (void)startCountdown{
SKLabelNode *countdownLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
__block short countdownValue = 3;
countdownLabel.position = CGPointMake(screenWidth/2, screenHeight/2 - countdownLabel.fontSize/2);
countdownLabel.zPosition = 100.0;
countdownLabel.text = [NSString stringWithFormat:@"%d", countdownValue];
countdownLabel.fontColor = [UIColor blackColor];
countdownLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeBaseline;
[self addChild:countdownLabel];
SKAction *zoomIn = [SKAction scaleTo:1.5f duration:0.9];
SKAction *fadeOut = [SKAction fadeAlphaTo:0.0f duration:0.1];
SKAction *updateCount = [SKAction customActionWithDuration:0.0 actionBlock:^(SKNode *node, CGFloat elapsedTime) {
SKLabelNode *textNode = (SKLabelNode *)node;
countdownValue --;
if (countdownValue == 0) {
textNode.text = @"PLAY!";
}
else{
textNode.text = [NSString stringWithFormat:@"%d", countdownValue];
}
textNode.alpha = 1.0f;
textNode.xScale = 1.0f;
textNode.yScale = 1.0f;
}];
SKAction *sequence = [SKAction sequence:@[zoomIn, fadeOut, updateCount]];
SKAction *repeat = [SKAction repeatAction:sequence count:4];
[countdownLabel runAction:repeat completion:^{
[countdownLabel removeFromParent];
}];
NSLog(@"completed!");
}
我已验证 startCountdown 实际上已结束。然而,完成块永远不会被调用。有什么想法吗?
谢谢
【问题讨论】:
标签: ios sprite-kit skaction skscene