Я создаю визуальный роман на быстрой игровой площадке с использованием набора Sprite. Поэтому я создал сцену размером с фоновое изображение.
Проблема, с которой я столкнулся, заключается в том, что моя сцена обрезается в liveView детской площадки.
Я считаю, что проблема связана с PlaygroundLiveViewSafeAreaContainer, и поэтому япопытался переопределить его с помощью:
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