缓慢的 Skscene 过渡 [英] Slow Skscene transition

查看:14
本文介绍了缓慢的 Skscene 过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个场景:Home 和 Play.与过渡到家庭场景相比,播放场景的过渡确实很慢.我认为这是因为在我的游戏场景中发生了更多的事情.有什么办法可以预加载播放场景吗?还是让过渡更加无缝?

I have two scenes: Home and Play. The transition to play scene is really slow compared to the transition to home scene. I think this is because there's more happing in my play scene. Is there any way I can preload play scene ? Or make the transition more seamless?

我对本论坛中的答案感兴趣预加载场景以防止延迟?但我不知道从哪里开始.我在哪里放置答案的 A 和 B 部分

I'm interested in the answer in this forum Preload a Scene to prevent lag? but I have no idea where to begin. Where do I place part A and B of the answer

这是我正在使用的

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)]))


    }    

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

Any other solution is fine.

谢谢

推荐答案

我这样做并且有效:在 HomeScenedidView 中放入 preloadGameScene()并且总是在家庭场景中:

I do this and works: in didView of HomeScene put preloadGameScene() And always in home scene:

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 类调用:

goToGameScene() is called by a button personal SKButton class:

    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))
            })

        })
    }

这篇关于缓慢的 Skscene 过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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