我在尝试做一个完成,将复盖得分从我SpriteKit现场。 我得到了下列代码现在,这显示出内的代码实际现场,但我想展示在图
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()
}
这里是功能:
// 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()
}
}
}
我认代码看起来是这样的:
import SwiftUI
import SpriteKit
struct PageTwo: View {
@State var gameScore = 0
var body: some View {
ZStack {
GameView()
ZStack {
Text("Score: \(gameScore)")
.foregroundColor(.white)
}
}
}
}
它表示的成绩,但不计,因此也许有人可以告诉我在哪里,我要错误在这里? 这SpriteKit+SwiftUI是新来的我仍然没有完全得到了它。