Estoy tratando de hacer un ZStack que se superpondrá a la Puntuación de mi SpriteKit escena. Tengo el siguiente código justo ahora, este tipo de obras que muestran el código dentro de la realidad de la escena, pero lo que quiero mostrar en la 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()
}
Esta es la función:
// 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()
}
}
}
Mi código de la Vista se parece a esto:
import SwiftUI
import SpriteKit
struct PageTwo: View {
@State var gameScore = 0
var body: some View {
ZStack {
GameView()
ZStack {
Text("Score: \(gameScore)")
.foregroundColor(.white)
}
}
}
}
Se trata de mostrar la Puntuación, pero no se cuenta, así que tal vez alguien me puede decir donde estoy pasando mal aquí? Este SpriteKit + SwiftUI es nuevo para mí y todavía no tengo.