gpt4 book ai didi

ios - 如何在 Swift 中从 SKScene 呈现 UiView

转载 作者:行者123 更新时间:2023-11-30 10:51:47 25 4
gpt4 key购买 nike

我正在制作一个游戏,我想从我的 MenuScene.swift (这是一个 SKScene)中呈现一个 UIView (用于我的游戏中的共享场景) ) 文件。我在 Stack Overflow 上搜索过类似的问题,但没有一个在我的游戏中起作用。谁能告诉我它是如何完成的?

菜单场景:

class MenuScene: SKScene {   
override func didMove(to view: SKView) {
backgroundColor = UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0)
addLabelsAndButtons()
}

func addLabelsAndButton() {

let shareButton = SKSpriteNode(imageNamed: "ShareButton")
shareButton.size = CGSize(width: frame.size.height/12, height: frame.size.height/12)
shareButton.position = CGPoint(x: frame.midX + shareButton.size.width/1.5, y: frame.minY + shareButton.size.height)
shareButton.name = "ShareButton"
addChild(shareButton)

}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if atPoint((touch.location(in: self))).name == "ShareButton" {
//Where I want to present my Share Scene!
}
}
}

最佳答案

您无法在 SKScene 内呈现 UIView,因为 SKScene 已针对处理游戏的 Sprite 渲染进行了优化,并且使用与 UIView 不同的技术堆栈。

您可以做的是将 UIView 添加到 SKView 添加到的父 View (也是 UIView)。这使您可以在游戏的 Sprite View 之上呈现更加静态的 View ,例如:得分 View 、HUD View 或菜单。

我在下面放了一个图表:

UIView
⮑ 0: SKView
⮑ 0: SKScene
⮑ 1: UIView

关于ios - 如何在 Swift 中从 SKScene 呈现 UiView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54386012/

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