gpt4 book ai didi

ios - 缓慢的场景转换

转载 作者:行者123 更新时间:2023-11-28 06:38:10 29 4
gpt4 key购买 nike

我有两个场景:Home 和 Play。与主场景的过渡相比,到比赛场景的过渡真的很慢。我认为这是因为我的游戏场景中有更多的快乐。有什么办法可以预加载播放场景吗?或者使过渡更加无缝?

我对这个论坛的答案很感兴趣Preload a Scene to prevent lag?但我不知道从哪里开始。我将答案的 A 部分和 B 部分放在哪里

这是我用的

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches
let location = touch.first!.locationInNode(self)
let node = self.nodeAtPoint(location)

if (node.name == "Balloon") {

let sceneAction = SKAction.runBlock({
let secondScene = Scene2(size: self.size)
let transition = SKTransition.fadeWithDuration(1)
secondScene.scaleMode = SKSceneScaleMode.AspectFill
self.scene!.view?.presentScene(secondScene, transition: transition)
})
PlayButton.runAction(SKAction.sequence([sound,SKAction.animateWithTextures(array, timePerFrame: 0.1),sceneAction,SKAction.waitForDuration(1)]))


}

任何其他解决方案都可以。

谢谢

最佳答案

我这样做并有效:在 HomeScenedidView 中放置 preloadGameScene()并且始终在家庭场景中:

fileprivate var nextScene: SKScene?

func preloadGameScene () {
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
self.nextScene = GameScene(fileNamed:"yoursksfilename")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
print("SCENE LOADED")
let loading = self.childNodeWithName("Loading") as? SKLabelNode
self.playButton?.hidden = false
self.playButton?.alpha = 0
//loading?.hidden = true
self.playButton?.runAction(SKAction.fadeAlphaTo(1.0, duration: 0.4))
loading!.runAction(SKAction.fadeAlphaTo(0.0, duration: 0.4))
})

})
}

goToGameScene() 由按钮个人 SKButton 类调用:

    func goToGameScene () {
guard let nextScene = nextScene else {return}
let transition = SKTransition.crossFadeWithDuration(0.5)
nextScene.scaleMode = .AspectFill
scene!.view?.presentScene(nextScene, transition: transition)
}

更新 SWIFT 3

fileprivate var nextScene: SKScene?

func preloadGameScene () {
let qualityOfServiceClass = DispatchQoS.QoSClass.background
let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
backgroundQueue.async(execute: {
self.nextScene = GameScene(fileNamed:"yoursksfilename")
DispatchQueue.main.async(execute: { () -> Void in
print("SCENE LOADED")
let loading = self.childNode(withName: "Loading") as? SKLabelNode
self.playButton?.isHidden = false
self.playButton?.alpha = 0
//loading?.hidden = true
self.playButton?.run(SKAction.fadeAlpha(to: 1.0, duration: 0.4))
loading?.run(SKAction.fadeAlpha(to: 0.0, duration: 0.4))
})

})
}

关于ios - 缓慢的场景转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38601845/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com