将视图从SKScene更改为ViewController

时间:2017-10-19 17:30:29

标签: ios swift augmented-reality xcode9 arkit

我正在使用ARKit制作游戏。我很难从SKSecene那里看到ARSCN的观点。

到目前为止,我有这个:

import Foundation
import SpriteKit

//Back button
let backToBrand = SKLabelNode(fontNamed: "Electric Boots")

class Lamborghini: SKScene {
    override func didMove(to view: SKView) {
        //Background
        let menuBackground = SKSpriteNode(imageNamed: "Background")
        menuBackground.setScale(1)
        menuBackground.position = CGPoint(x: self.size.width/2, y: 

self.size.height/2)
    menuBackground.zPosition = 0
    self.addChild(menuBackground)

    //Back button
    backToBrand.text = "Back"
    backToBrand.fontSize = 50
    backToBrand.fontColor = SKColor.white
    backToBrand.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.left
    backToBrand.position = CGPoint(x: self.size.width*0.05, y: self.size.height*0.67)
    backToBrand.zPosition = 1
    self.addChild(backToBrand)

    //Test button
    let test = SKLabelNode(fontNamed: "Electric Boots")
    test.text = "test AR"
    test.fontSize = 100
    test.fontColor = SKColor.white
    test.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
    test.zPosition = 2
    test.name = "test"
    self.addChild(test)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch: AnyObject in touches {
        let pointOfTouch = touch.location(in: self)
        let nodeITapped = atPoint(pointOfTouch)

        if nodeITapped == backToBrand {
            let sceneToMOveTo = BrandMenu(size: self.size)
            sceneToMOveTo.scaleMode = self.scaleMode
            let sceneTransition = SKTransition.fade(withDuration: 0.5)
            self.view!.presentScene(sceneToMOveTo, transition: sceneTransition)

        }
        if nodeITapped.name == "test"{
            let sceneToMOveTo = ARView(size: self.size)
            sceneToMOveTo.scaleMode = self.scaleMode
            let sceneTransition = SKTransition.fade(withDuration: 0.5)
            self.view!.presentScene(sceneToMOveTo, transition: sceneTransition)
        }
    }
}

有问题的部分是:

if nodeITapped.name == "test" {
    let sceneToMOveTo = ARView(size: self.size)
    sceneToMOveTo.scaleMode = self.scaleMode
    let sceneTransition = SKTransition.fade(withDuration: 0.5)
    self.view!.presentScene(sceneToMOveTo, transition: sceneTransition)
}

AR场景位于Main.Storyboard内的ViewController中。

我无法让游戏场景移动到ViewController并向后移动。

0 个答案:

没有答案