重新加载 SKScene 后 SKAction 不是 运行
SKAction not running after SKScene reloaded
我正在使用 iOS SpriteKit 构建游戏。我有一个常规的 UIViewController
"Chooser" 可以进入第二个 VC 来加载 SKScene。 SKScene
加载 SKSprites
并通过 SKAction
在屏幕上移动它们。当我 运行 第一轮时效果很好。
完成一场比赛后,我们 return 到 Chooser
准备下一轮比赛。我用相同的 SKScene
重新加载相同的 VC。这次创建了 Sprites,但 SKAction
没有 运行。我添加了一堆日志语句来追踪它。
这是带有 SKAction
的代码:
NSInteger startZone = [TPMathUtilities randomOffscreenStartZone];
CGPoint startPointONE = [TPMathUtilities OFFScreenPointFinder:startZone];
NSInteger finishZone = [TPMathUtilities finishZoneFinder:startZone];
CGPoint finishPointONE = [TPMathUtilities OFFScreenPointFinder:finishZone];
NSLog(@"startPointONE = %f %f finishPointONE = %f %f", startPointONE.x,startPointONE.y,finishPointONE.x,finishPointONE.y);
newTap.position = startPointONE;
CGFloat distanceToOffScreenPt = [TPMathUtilities distanceBetweenTwoPoints:startPointONE toPoint:finishPointONE];
CGFloat movementDuration = distanceToOffScreenPt/[[TPGameData data] tapBaseGeneratorVelocity];
NSLog(@"movementDuration = %f", movementDuration);
newTap runAction:[SKAction sequence:@[[SKAction runBlock:^{NSLog(@"starting TAP ACTIONS ");}],
[SKAction moveTo:finishPointONE duration:movementDuration],
[SKAction removeFromParent]]]];
这是第一轮的日志,可以看到"starting TAP ACTIONS"
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.511158
startPointONE = -50.000000 740.000000 finishPointONE = 913.000000 -50.000000
movementDuration = 4.529381
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.512250
startPointONE = 1064.000000 158.000000 finishPointONE = 521.000000 808.000000
movementDuration = 3.079871
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.561383
startPointONE = 1064.000000 451.000000 finishPointONE = -50.000000 755.000000
movementDuration = 4.199035
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.507709
startPointONE = 921.000000 808.000000 finishPointONE = -50.000000 110.000000
movementDuration = 4.348527
UPDATE after Sprite Added
starting TAP ACTIONS
这是没有 SKAction 的第二轮:
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.813655
startPointONE = 1064.000000 440.000000 finishPointONE = -50.000000 7.000000
movementDuration = 4.346155
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.813989
startPointONE = 437.000000 -50.000000 finishPointONE = 652.000000 808.000000
movementDuration = 3.216464
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.806389
startPointONE = 992.000000 -50.000000 finishPointONE = 856.000000 808.000000
movementDuration = 3.158952
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.811594
startPointONE = -50.000000 146.000000 finishPointONE = 1064.000000 746.000000
movementDuration = 4.601108
UPDATE after Sprite Added
我创建 SKScene
的代码保持不变,上面的代码没有改变。猜猜为什么动作没有在第二轮的 Sprite 上激活?
@DFrog 引导我朝着正确的方向前进。问题出在展开的 segue 中。我的应用程序有一个初始 VC,玩家可以在其中选择一个游戏 'level.' 它会转到包含 SKScene 的第二个 VC。然后在游戏结束时 'unwinds' 返回选择器VC。
我删除了 VC 之间的所有 segues/connections,并按照此处的建议创建了一个新的 unwind segue:
Unwind segue in a nutshell
现在效果很好。谢谢大家
我正在使用 iOS SpriteKit 构建游戏。我有一个常规的 UIViewController
"Chooser" 可以进入第二个 VC 来加载 SKScene。 SKScene
加载 SKSprites
并通过 SKAction
在屏幕上移动它们。当我 运行 第一轮时效果很好。
完成一场比赛后,我们 return 到 Chooser
准备下一轮比赛。我用相同的 SKScene
重新加载相同的 VC。这次创建了 Sprites,但 SKAction
没有 运行。我添加了一堆日志语句来追踪它。
这是带有 SKAction
的代码:
NSInteger startZone = [TPMathUtilities randomOffscreenStartZone];
CGPoint startPointONE = [TPMathUtilities OFFScreenPointFinder:startZone];
NSInteger finishZone = [TPMathUtilities finishZoneFinder:startZone];
CGPoint finishPointONE = [TPMathUtilities OFFScreenPointFinder:finishZone];
NSLog(@"startPointONE = %f %f finishPointONE = %f %f", startPointONE.x,startPointONE.y,finishPointONE.x,finishPointONE.y);
newTap.position = startPointONE;
CGFloat distanceToOffScreenPt = [TPMathUtilities distanceBetweenTwoPoints:startPointONE toPoint:finishPointONE];
CGFloat movementDuration = distanceToOffScreenPt/[[TPGameData data] tapBaseGeneratorVelocity];
NSLog(@"movementDuration = %f", movementDuration);
newTap runAction:[SKAction sequence:@[[SKAction runBlock:^{NSLog(@"starting TAP ACTIONS ");}],
[SKAction moveTo:finishPointONE duration:movementDuration],
[SKAction removeFromParent]]]];
这是第一轮的日志,可以看到"starting TAP ACTIONS"
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.511158
startPointONE = -50.000000 740.000000 finishPointONE = 913.000000 -50.000000
movementDuration = 4.529381
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.512250
startPointONE = 1064.000000 158.000000 finishPointONE = 521.000000 808.000000
movementDuration = 3.079871
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.561383
startPointONE = 1064.000000 451.000000 finishPointONE = -50.000000 755.000000
movementDuration = 4.199035
UPDATE after Sprite Added
starting TAP ACTIONS
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.507709
startPointONE = 921.000000 808.000000 finishPointONE = -50.000000 110.000000
movementDuration = 4.348527
UPDATE after Sprite Added
starting TAP ACTIONS
这是没有 SKAction 的第二轮:
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.813655
startPointONE = 1064.000000 440.000000 finishPointONE = -50.000000 7.000000
movementDuration = 4.346155
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.813989
startPointONE = 437.000000 -50.000000 finishPointONE = 652.000000 808.000000
movementDuration = 3.216464
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.806389
startPointONE = 992.000000 -50.000000 finishPointONE = 856.000000 808.000000
movementDuration = 3.158952
UPDATE after Sprite Added
UPDATE variables: localGenMult= 0.800000 tapBaseGen= 0.800000 gameInterval= 0.811594
startPointONE = -50.000000 146.000000 finishPointONE = 1064.000000 746.000000
movementDuration = 4.601108
UPDATE after Sprite Added
我创建 SKScene
的代码保持不变,上面的代码没有改变。猜猜为什么动作没有在第二轮的 Sprite 上激活?
@DFrog 引导我朝着正确的方向前进。问题出在展开的 segue 中。我的应用程序有一个初始 VC,玩家可以在其中选择一个游戏 'level.' 它会转到包含 SKScene 的第二个 VC。然后在游戏结束时 'unwinds' 返回选择器VC。
我删除了 VC 之间的所有 segues/connections,并按照此处的建议创建了一个新的 unwind segue: Unwind segue in a nutshell
现在效果很好。谢谢大家