SKScene 在空闲时变得无响应 [英] SKScene becomes unresponsive while being Idle

查看:52
本文介绍了SKScene 在空闲时变得无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个 SceneKit 游戏.所有游戏都在一个场景中,当游戏结束时,精灵套件叠加层充当游戏结束屏幕,当他们再次点击播放时,精灵套件标签消失,游戏在同一场景中全部重置.

Hello I have a SceneKit game. All the game play is in one scene and when the game is over the sprit kit overlay acts as a game over screen and when they hit play again the sprite kit labels disappear and the game resets all in the same scene.

我的发行即将结束.如果用户在几秒钟内点击重播按钮,那么一切都会顺利.但是如果用户在游戏上超过五秒钟,那么场景就会冻结.我真的很困惑,因为应用程序在冻结时处于空闲状态并且我没有收到任何错误.此外,游戏期间的内存和 CPU 使用率比游戏期间低得多.此外,该应用程序本身不会冻结,就像我单击菜单按钮一样,它会很好地转换到新的视图控制器.

My issuing is coming in the game over. If the user hits the replay button within a few seconds then everything goes well. But if the user sits on the game over place for over five seconds then the scene freezes. I am really confused as the app is idle when it freezes and I am receiving no errors. Also the memory and CPU usage are much lower during game over that during game play. Also that app itself is not frozen as if I click the menu button it transitions to a new view controller just fine.

没有内存泄漏或错误,我真的不知道从哪里开始寻找问题所在?有人可以指出我正确的方向

With no memory leaks or errors I really have no idea where to begin looking for whats wrong? Can someone point me in the right direction

更深入地了解正在发生的事情:该游戏是一款使用物理模拟的短半分钟动作游戏.有一个计时器设置为每 0.01 秒触发一次,这会影响游戏的进行.当游戏结束时(由一个节点与另一个节点碰撞引起),玩家节点被移除,一个变量被设置为 false 以便当游戏计时器触发时什么也不会发生,并且在 sprit kit 覆盖层中创建了一堆标签节点充当游戏结束菜单.

A little more insight to whats going on: The game is a short half minute action game that uses the physics simulation. There is a timer set to fire every 0.01 seconds that affects the game play. When the game is over (caused by one node colliding with another) the players node is removed, a variable is set to false so that when the game timer fires nothing happens, and a bunch of label nodes are created in the sprit kit overlay that act as the game over menu.

如果用户在五秒内点击重播,一切都会很好.单击重播隐藏所有标签,在起始位置创建玩家节点,并将计时器变量设置回真.

Again everything works great if the user clicks replay within fivish seconds. Clicking replay hides all the labels, creates the players node in the starting position, and sets the timers variable back true.

这是设置场景的代码

// create a new scene
scene = SCNScene()
sceneView = SCNView()
sceneView.frame = self.view.frame
sceneView.autoresizingMask = UIViewAutoresizing.allZeros
sceneView.scene = scene
sceneView.autoenablesDefaultLighting = false
sceneView.allowsCameraControl = false
sceneView.showsStatistics = false
sceneView.backgroundColor = UIColor.blackColor()
scene.physicsWorld.gravity = SCNVector3Make(0, -30, 0)
scene.physicsWorld.contactDelegate = self
self.view = sceneView
self.MarbleGeo = SCNSphere(radius: 1.3)
hud = Hud(size: self.view.frame.size, game: self)
sceneView.overlaySKScene = hud

编辑

我找到了代码崩溃的地方.当再次单击按钮时,所有标签都应该沿着这些线移动或淡出或产生一些效果.无论如何,重新启动游戏的方法调用是在这些效果中的最后一个完成时.这是代码

I have located where the code is breaking down. When the again button is clicked all the labels are supposed to move or fade out or some effect along those lines. Anyways the method call to restart the game is in the completion of the last of one of those effects. Here is the code

println("Before check")
MenuLabel.runAction(moveButtonsOut, completion: { () -> Void in
    self.scoreLabel.removeFromParent()
    self.MyGame.Setup()
    self.MyGame.Restart(true, Level: self.MyGame.level)
    self.startTimer()
    println("should have called the game to begin by now")
    //self.playing = true
    //self.MyGame.addMarble()
})

第一条语句被记录,但完成块内部的语句没有被记录.所以我想我现在的问题变成了为什么在游戏冻结后这些操作没有被运行和完成?

The first statement is logged, but the one on the inside of the completion block is not. So I guess the my question now changes to why aren't these actions being run and completed once the game freezes?

编辑

看起来 SKActions 正在被踢出队列.在游戏结束场景中,一些标签会一遍又一遍地放大和缩小,有些则淡入淡出,什么都没有.无论如何,当所有这些都发生在重播按钮上时,效果很好,没有错误.当所有这些操作冻结时,按钮不再起作用,因为重启方法在完成后永远不会被调用.我尝试将重新启动方法放在完成之外,当它们被调用时,所有动作都被解冻了,它们都急于完成,看起来很糟糕.所以总结一下就是暂停 SKActions

It appears that the SKActions are being kicked from the que. While in the game over scene some labels are enlarging and shrinking over and over and some fade in and out and what not. Anyways when all this is going on the replay button works great, no errors. When all these actions freeze that is when the button no longer works because the restart methods never get called on upon completion. I tried placing the restart methods outside of completion and when they were called all the actions because unfrozen and they all rush to complete and it looks awful. So to sum up something is pausing the SKActions

希望这会有所帮助.

推荐答案

您的 SceneKit 场景正在播放吗?当你有

is your SceneKit scene playing ? A scene is playing when you either have

  • scene.playing = YES
  • SCNAction 正在运行的实例
  • 隐式或显式动画运行

SpriteKit 场景叠加仅在 SceneKit 场景刷新时才刷新.因此,如果 SceneKit 场景不重新显示叠加层中设置的操作,则可能无法运行.

The SpriteKit scene overlay is refreshed only when the SceneKit scene is. So if the SceneKit scene does not redisplay the actions set in the overlay might not run.

解决方案可能是设置 playing 属性或向 SceneKit 对象而不是 SpriteKit 对象添加动作.

A solution might be to set the playing property or to add actions to SceneKit objects instead of SpriteKit objects.

这无关紧要,但尽量远离计时器.SceneKit 提供了多个游戏循环回调,可让您做您想做的事.

This is unrelated but try to keep away from timers. SceneKit provides several game loop callbacks that will allow you to do what you want.

这篇关于SKScene 在空闲时变得无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆