Snažím se, aby ZStack, že bude overlay Skóre z mého SpriteKit scény. Mám následující kód, teď to funguje ukazuje kód ve skutečnosti scénu, ale chci ukázat, že v Pohledu
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()
}
Zde je funkce:
// 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()
}
}
}
Můj Názor, kód vypadá takto:
import SwiftUI
import SpriteKit
struct PageTwo: View {
@State var gameScore = 0
var body: some View {
ZStack {
GameView()
ZStack {
Text("Score: \(gameScore)")
.foregroundColor(.white)
}
}
}
}
Je zobrazeno Skóre, ale nepočítám to, takže možná, že někdo mi může říct, kde jsem jít špatně? Tento SpriteKit + SwiftUI je pro mě nová a ještě ne tak docela dostal.