我在iOS 7.1上的Sprite Kit崩溃了。我尝试用Xcode 5.0.2和5.1构建。结果是一样的。在iOS 7.1设备上仍然崩溃。
以下是截图。
我找到了导致崩溃的代码。
- (WATDirection *)panDown {
WATDirection *direction = [[WATDirection alloc] init];
CGFloat newY = 830;
@weakify(self)
[direction addStartHandler:^(WATDirection *direction) {
@strongify(self)
self.panningDown = YES;
[self runAction:[self animateNextArrowFadeOut] withKey:@"next_arrow"];
// Move the scene
SKAction *panDown = [SKAction moveToY:newY duration:1.5];
panDown.timingMode = SKActionTimingEaseInEaseOut;
[self.rootNode runAction:panDown withKey:@"panDown"];
// Fade in the pipes
SKNode *pipes = [self.rootNode childNodeWithName:@"pipes"];
SKAction *fadeIn = [SKAction sequence:@[
[SKAction waitForDuration:0.3],
[SKAction fadeAlphaTo:1 duration:0.6]
]];
[pipes runAction:fadeIn withKey:@"fadeIn"];
[pipes enumerateChildNodesWithName:@"pipe" usingBlock:^(SKNode *node, BOOL *stop) {
SKAction *fadeIn = [SKAction sequence:@[
[SKAction waitForDuration:1.1],
[SKAction fadeAlphaTo:1 duration:0.6],
]];
[node runAction:fadeIn withKey:@"fadeIn"];
}];
// Fade out the overlay
SKNode *pipesOverlay = [pipes childNodeWithName:@"pipes_overlay"];
SKAction *fadeOut = [SKAction sequence:@[
[SKAction waitForDuration:3.0],
[SKAction fadeAlphaTo:0 duration:0.5],
[SKAction removeFromParent]
]];
[pipesOverlay runAction:fadeOut withKey:@"fadeOut"];
[self runAction:[SKAction sequence:@[
[SKAction waitForDuration:3.5],
[SKAction runBlock:^{
[direction finish];
}]
]]];
}];
[direction addFinishHandler:^(WATDirection *direction) {
@strongify(self)
[self runAction:[self animateNextArrowFadeIn] withKey:@"next_arrow"];
self.panningDown = NO;
self.pannedDown = YES;
}];
[direction addCancelHandler:^(WATDirection *direction) {
@strongify(self)
SKAction *panDown = [SKAction moveToY:newY duration:0];
[self.rootNode runAction:panDown withKey:@"panDown"];
SKNode *pipesOverlay = [self childNodeWithName:@"//pipes_overlay"];
[pipesOverlay removeFromParent];
[self runAction:[self animateNextArrowFadeIn] withKey:@"next_arrow"];
self.panningDown = NO;
self.pannedDown = YES;
}];
return direction;
}
这两行是问题所在:
@strongify(self)
[self runAction:[self animateNextArrowFadeIn] withKey:@"next_arrow"];
有关于此的任何想法吗?
答案 0 :(得分:1)
发现问题。有两个动作使用相同的animationKey @“next_arrow”。
[self runAction:[self animateNextArrowFadeIn] withKey:@"next_arrow"];
在第一个动作结束之前,第二个动作开始。第二个操作尝试从队列中删除带有该键的动画但是没有对该键执行任何操作,因为第一个操作从队列中删除了该键。
修复方法是重命名第二个动画的动作键。
[self runAction:[self animateNextArrowFadeIn] withKey:@"next_arrow_down"];
感谢大家的支持!