Eu estou tentando fazer um ZStack que irá se sobrepor a Pontuação do meu SpriteKit cena. Eu tenho o seguinte código para a direita agora, isso funciona mostrando o código dentro do realmente cena, mas eu quero mostrar em Vista
import SwiftUI
import SpriteKit
var gameScore = 0
class GameScene: SKScene, SKPhysicsContactDelegate {
let removeLabel = SKAction.sequence([SKAction.fadeIn(withDuration: 0.3), SKAction.wait(forDuration: 0.8), SKAction.fadeOut(withDuration: 0.3)])
override func sceneDidLoad() {
super.sceneDidLoad()
}
Aqui é a função:
// MARK: - Add Score
func addScore(){
if gameScore < 250 {
gameScore += 1
scoreLabel.text = String(format: "%06d", gameScore)
let possibleScores: Set = [10, 20, 30, 40, 50, 65, 80, 95, 110, 125, 150, 175, 200, 250]
if possibleScores.contains(gameScore) {
startNewLevel()
}
} else {
gameScore += 2
scoreLabel.text = String(format: "%06d", gameScore)
let possibleScores: Set = [10, 20, 30, 40, 50, 65, 80, 95, 110, 125, 150, 175, 200, 250]
if possibleScores.contains(gameScore) {
startNewLevel()
}
}
}
A meu Ver o código tenha esta aparência:
import SwiftUI
import SpriteKit
struct PageTwo: View {
@State var gameScore = 0
var body: some View {
ZStack {
GameView()
ZStack {
Text("Score: \(gameScore)")
.foregroundColor(.white)
}
}
}
}
Ele está mostrando a Pontuação, mas não contar a ele, talvez por isso alguém pode me dizer onde eu estou indo errado aqui? Este SpriteKit + SwiftUI é novo para mim, e ainda não é o bastante tenho-o.