如何绕过PlaygroundLiveViewSafeAreaContainer?

时间:2019-10-15 16:49:06

标签: xcode11 swift5

我正在使用Sprite Kit在迅速的操场上制作视觉小说。 所以我做了一个背景图片大小的场景。

我的问题是我的场景在操场的liveView中被裁剪了。

我认为问题出在PlaygroundLiveViewSafeAreaContainer,所以我尝试用:p覆盖它

override var liveViewSafeAreaGuide: UILayoutGuide {
        return UILayoutGuide()
    }

但是我收到“属性不会从其超类覆盖任何属性”错误

通过使用TVOS平台,我可以获得更大的安全区域,但是随后我松开了“触摸”功能。

这是我的代码:

import SpriteKit
import PlaygroundSupport



let messDic = ...
var messPosition = 1
var backGround = SKSpriteNode(imageNamed: "corridor.jpg")
var farLeftPortrait = SKSpriteNode(imageNamed: "token_1.png")
farLeftPortrait.alpha = 0
let gameView = SKView(frame: backGround.frame)
public let textViewFrame = CGRect(x: .zero, y: .zero, width: backGround.frame.width, height: backGround.frame.height/3)

let titleScreenBackground = SKSpriteNode(color: .black, size: backGround.size)


class FirstScreen : SKScene {

    override var liveViewSafeAreaGuide: UILayoutGuide {
        return UILayoutGuide()
    }

    let startButton = SKLabelNode.init(text: "Start!")
    let gameTitle = SKLabelNode.init(text: "This is a title")
    let gameDescription = SKLabelNode(text: "A Triforce Games Production")
    let firstScreen = SKScene.init(size: backGround.size)

    override init() {
        super.init(size: backGround.size)
        self.startButton.color = .white
        self.gameTitle.color = .white
        self.gameDescription.color = .white

        self.startButton.position = .init(x: backGround.frame.width/2, y: backGround.frame.height*(2/5))
        self.gameTitle.position = .init(x: backGround.frame.width/2, y: backGround.frame.height*(4/5))
        self.gameDescription.position = .init(x: backGround.frame.width/2, y: backGround.frame.height-35)

        self.addChild(startButton)
        self.addChild(gameTitle)
        self.addChild(gameDescription)
    }



    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        if let location = touches.first?.location(in: self) {
            nodeTapped(node: self.atPoint(location))
        }
    }

    func nodeTapped(node : SKNode) {
        if node === self.startButton {

            gameView.presentScene(GameScene())
        }
    }

}

class GameScene: SKScene {

    let textBox = SKSpriteNode(color: .black, size: textViewFrame.size)
    var labelField = SKLabelNode.init(text: "")
    var sampleText = "As you enter the dark hallway, a sense of dread grabs you"

    override init() {
        super.init(size: backGround.size)
        self.addChild(backGround)

        self.textBox.anchorPoint = .init(x: 0, y: 0)
        self.textBox.alpha = 0.5
        self.addChild(textBox)

        self.labelField.text = sampleText
        self.labelField.color = .white
        self.labelField.alpha = 1
        self.labelField.position = .init(x: textViewFrame.width/2, y: textViewFrame.height/2)
        self.addChild(labelField)
        }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.labelField.text = messDic[messPosition]
        farLeftPortrait.alpha = 0
        print("I was here \(messPosition)")
        messPosition += 1
        if messPosition == 4{
            self.labelField.text = "Hello potion seller"
            farLeftPortrait.alpha = 1
        }

    }



}

gameView.presentScene(FirstScreen())


PlaygroundPage.current.liveView = gameView

0 个答案:

没有答案