swift - 如何在 2 个 skscenes 之间转换

标签 swift sprite-kit transition scene

我一直在尝试在我的 2 个 skscenes 之间转换最长的时间。对于新的 swift ,没有任何效果。我已经尝试在 gameviewcontroller 中使用过渡

if let view = self.view {
   // Load the SKScene from 'GameScene.sks'
   if let scene = SKScene(fileNamed: "NextLevelTab") {
      // Set the scale mode to scale to fit the window
      scene.scaleMode = .aspectFill

      // Present the scene
      view.presentScene(scene)
   }
   view.ignoresSiblingOrder = true                 
   view.showsFPS = true
   view.showsNodeCount = true
 }

并尝试使用我在网上找到的另一种方法

let reveal = SKTransition.reveal(with: .down, duration: 1)
let MainMenuTab = GameScene(size: CGSize(width: 1024, height: 768))
scene?.view?.presentScene(MainMenuTab,transition: reveal)

但没有任何效果。我做错了什么吗?

最佳答案

以下代码适用于使用 init() 函数呈现场景且没有 SKS 对应文件的情况

let reveal = SKTransition.reveal(with: .down, duration: 1)
let MainMenuTab = GameScene(size: CGSize(width: 1024, height: 768))
scene?.view?.presentScene(MainMenuTab,transition: reveal)

当您有 SKS 文件时,使用以下内容,其中第一个 GameScene 是类名,引号中的 GameScene 是 sks 文件的名称

if let scene = GameScene(fileNamed: "GameScene") { }

关于swift - 如何在 2 个 skscenes 之间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48292448/

相关文章:

swift 如何解析复杂的json?

ios - 改变导航栏的颜色

swift - Spritekit ApplyImpulse 跳得太高

iphone - 将场景的框架设置为 iPhone 屏幕的大小

html - CSS - 在 safari 中过渡不流畅

swift - 减少日期计算所需的时间

ios - 如何找到选定的 Collection View Cell 的索引路径?

javascript - three.js 使用颜色过渡动画网格 (tween.js)

swift - 如何在不改变其位置的情况下旋转 SKNode?

javascript - 在延迟加载页面时触发 CSS 转换