我如何获得一个调用aUIView。presentScene(aSKScene, transition: aSKTransition)与aUIView.addSubview.
,
的过渡,有零问题. .与SKTransition
UITextField
先发生SKTransition
-不一致
同样,UITextField
被植入ViewController
的view
中,等待SKTransition
赶上来
func showScene(theSceneName: String) {
if let ourScene = SKScene(fileNamed: theSceneName) {
addTextFieldToVC(toSceneName: theSceneName)
// NB: theSceneName is passed by Reference so we can
// return here before we call presentScene(...)
addGamePiecesToScene(toScene: theSceneName)
if let theView = self.view as! SKView? {
theView.ignoresSiblingOrder = true
theView.showsFPS = true
theView.showsNodeCount = true
// Finally, present the scene
let theTransition = SKTransition.doorway(withDuration: 2.0)
theView.presentScene(ourScene, transition: theTransition)
}
} // if let ourScene
} // showScene
func addTextFieldToVC(toSceneName: String) {
if (toSceneName == "GameScene") {
if let theView = self.view as! SKView? {
aUITextField = UITextField(frame:CGRectMake(x: aXValue, y: aYValue))
theView.addSubview(aUITextField!)
}
}
}
func addGamePiecesToScene(toScene: SKScene) {
myRoom = SKSpriteNode(texture: SKTexture(imageNamed: roomImg))
myRoom!.zPosition = roomZposition
// etc with .size, .position
toScene.addChild(myRoom!)
}
如上所示,我首先添加UITextField,然后添加SKSpriteNode图像。
但是它们不同步使用SKTransition。它们只同步出现在而不同步SKTransition。
fww,我在showScene
中尝试过这个序列,但没有变化:
theView.presentScene(theSceneName, transition: theTransition)
DispatchQueue.main.async {
addTextFieldToVC(toSceneName: theSceneName)
}
我也开始尝试完成处理程序:
override func viewDidLoad() {
super.viewDidLoad()
setupScene()
// Completion Handler for showScene()
showModifiedScene {
if thisSceneName == "GameScene" { // a global var
addTextFieldToVC(toSceneName: thisSceneName!)
}
}
} // viewDidLoad
// modified for callback option??
func showScene(theSceneName: String) {
if let ourScene = SKScene(fileNamed: theSceneName) {
addGamePiecesToScene(toScene: ourScene)
showModifiedScene()
} // if let ourScene
} // showScene
func showModifiedScene(completionBlock: () -> Void) {
if thisSceneName == "GameScene" { // a global var
if let ourScene = SKScene(fileNamed: thisSceneName!) {
if let theView = self.view as! SKView? {
theView.ignoresSiblingOrder = true
theView.showsFPS = true
theView.showsNodeCount = true
let theTransition = SKTransition.doorway(withDuration: 2.0)
theView.presentScene(ourScene, transition: theTransition)
}
}
completionBlock()
}
} // showModifiedScene
,,的过渡,有零问题. .与SKTransition
UITextField
先发生然后是SKTransition
- not in uni
我是仍然我在纠结这个…但我觉得是时候叫援军了!在等待髑髅地的时候,我还会继续工作。
尝试添加文本视图,然后将对presentScene()
的调用包装在对DispatchQueue.main.async()
的调用中。
这样,文本字段将在您开始显示视图之前添加到视图中。