我一直在試圖弄清楚如何在SKScene中呈現一個UIViewController。如何在SKScene中顯示UIViewController?
更具體地說,我在GameScene.swift上工作,當圖像被按下時,我想呈現uiviewcontroller。
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
backgroundColor = SKColor.blackColor()
var timeBetweenDots = NSTimer.scheduledTimerWithTimeInterval(0.35, target: self, selector: Selector("spawnWhiteDots"), userInfo: nil, repeats: true)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
func spawnWhiteDots(){
var dotWhite = SKSpriteNode(imageNamed: "whiteDot.png")
dotWhite.name = "destroyWhiteDot"
var randomDotPlacement = arc4random() % 9
switch (randomDotPlacement){
case 1:
dotWhite.position = CGPointMake(self.size.width/2.92, self.size.height/1)
break
case 2:
dotWhite.position = CGPointMake(self.size.width/1.81, self.size.height/1)
break
case 3:
dotWhite.position = CGPointMake(self.size.width/2.24, self.size.height/1)
break
case 4:
dotWhite.position = CGPointMake(self.size.width/1.52, self.size.height/1)
break
case 5:
dotWhite.position = CGPointMake(self.size.width/2.92, self.size.height/1)
break
case 6:
dotWhite.position = CGPointMake(self.size.width/2.24, self.size.height/1)
break
case 7:
dotWhite.position = CGPointMake(self.size.width/1.52, self.size.height/1)
break
case 8:
dotWhite.position = CGPointMake(self.size.width/1.81, self.size.height/1)
break
default:
break
}
let fallAction = SKAction.moveToY(-50, duration: 3.0)
dotWhite.runAction(SKAction.repeatActionForever(fallAction))
addChild(dotWhite)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = (touch as UITouch).locationInNode(self)
if let gameOverDot = self.nodeAtPoint(location).name {
if gameOverDot == "destroyWhiteDot"{
self.removeChildrenInArray([self.nodeAtPoint(location)])
///when the image is pressed I want to present the UIViewController here the name of the viewController is gameOverScene
}
}
}
}
可能的重複[如何從SKScene提供UIViewController?](http://stackoverflow.com/questions/19438719/how-do-i-present-a-uiviewcontroller-from-skscene) – JAL