I'm stuck on trying to figure out how to present a UIViewController in a SKScene.
To be more specific I'm working on GameScene.swift and when a image is pressed I want to present the 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
}
}
}
}