简体   繁体   English

重新加载SKScene后,SKAction无法运行

[英]SKAction not running after SKScene reloaded

I'm building a game using iOS SpriteKit. 我正在使用iOS SpriteKit构建游戏。 I have a regular UIViewController "Chooser" that segues into a second VC that loads a SKScene. 我有一个常规的UIViewController “ Chooser”,可以插入另一个加载SKScene的VC。 The SKScene loads SKSprites and moves them via SKAction across the screen. SKScene加载SKSprites ,并通过SKAction在屏幕上移动它们。 When I run the first round it works great. 当我进行第一轮比赛时,效果很好。

After completing a game we return to the Chooser to setup the next round. 完成游戏后,我们返回选择Chooser进行下一轮设置。 I reload the same VC with same SKScene . 我用相同的SKScene重新加载了相同的VC。 This time the Sprites are created but the SKAction does not run. 这次创建了Sprites,但是SKAction没有运行。 I added a bunch of logs statements to track it down. 我添加了一堆log语句来跟踪它。

Here's the code with the 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]]]];

Here's the log for the first round, you can see the "starting TAP ACTIONS" 这是第一轮的日志,您可以看到“启动TAP动作”

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

Here's the second round with out the SKAction: 这是第二轮没有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 

My code for creating the SKScene remains the same, and the code above does not change. 我创建SKScene的代码保持不变,并且上面的代码没有更改。 Any guess why the action is not activating on the Sprite the second round? 有人猜测为什么第二轮Sprite上的动作未激活吗?

@DFrog headed me in the right direction. @DFrog带我朝正确的方向前进。 The problem was in the unwind segue. 问题出在顺风顺水。 My app has an initial VC where players choose a game 'level.' 我的应用程序有一个初始VC,玩家可以在其中选择游戏的“关卡”。 It segues to a second VC containing the SKScene. 它搜索到包含SKScene的第二个VC。 It then 'unwinds' back to the chooserVC at the end of the game. 然后,它在游戏结束时“退回”到chooserVC。

I deleted all segues/connections between the VC's and made a new unwind segue following the advice here: Unwind segue in a nutshell 我删除了VC之间的所有segue /连接,并按照以下建议进行了新的放松: 概述

It now works great. 现在效果很好。 Thanks all. 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM