【发布时间】:2015-05-07 01:51:04
【问题描述】:
好的,所以我一直试图在整个互联网上找到这个问题的答案,似乎我几乎明白了。所以我所做的是我在一个类之外声明了我的纹理图集变量,以便它们在我的项目中是全局的。像这样的:
import SpriteKit
import CoreMotion
let myAtlas1 = SKTextureAtlas(named: "atlas1")
let myAtlas2 = SKTextureAtlas(named: "atlas2")
let myAtlas3 = SKTextureAtlas(named: "atlas3")
class GameScene: SKScene, SKPhysicsContactDelegate {
然后,在我的 GameViewController 中,我正在预加载它们,完成后我将展示我的 GameScene,如下所示:
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
SKTextureAtlas.preloadTextureAtlases([myAtlas1, myAtlas2, myAtlas3], withCompletionHandler: {() -> Void in
NSLog("completed")
self.startScene()
})
}
func startScene() {
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.showsPhysics = false
skView.ignoresSiblingOrder = true
let scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFit
scene.size = skView.bounds.size
skView.presentScene(scene)
}
当我运行游戏时,我的 LaunchImage 出现后,会弹出一个灰屏,然后将我带到游戏中。但是播放器不再工作了!现在它无法移动或其他任何东西..
【问题讨论】:
-
好问题,我也想知道。如果我不得不冒险猜测,它将成为 GameScene 类的一部分。根据我的经验,GameViewController 的工作只包含 SKView,而在施加与游戏相关的内容方面没有更多作用。
-
谢谢@KelvinLau 我在网上找遍了这方面,但仍然无法弄清楚它是如何工作的,所以如果你到目前为止发现了什么,请告诉我!
-
如果您编辑/更新您的问题,在“编辑”或“更新”之后将主要更改放在原始问题下方可能会很有趣。随着原始问题的重大变化,其他人将无法理解已经给出的答案。最美好的祝愿:-)
-
嘿@Thesaurus03 你解决了这个问题吗?我在预加载纹理时遇到问题,完成后,代码块不会运行。
标签: ios swift sprite-kit sktextureatlas