SwiftUI SpriteView问题-已停止添加节点
我复制了以下代码示例或相同教程: 而且效果很好。之后,我想显示用户单击了多少次(添加了节点)。我使用了@Binding PropertyRapper,之后应用程序就停止正常工作了。我修不好。SwiftUI SpriteView问题-已停止添加节点,swiftui,spriteview,Swiftui,Spriteview,我复制了以下代码示例或相同教程: 而且效果很好。之后,我想显示用户单击了多少次(添加了节点)。我使用了@Binding PropertyRapper,之后应用程序就停止正常工作了。我修不好。 如果要注释score+=1-一切重新开始 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { guard let touch = touches.first else { return }
如果要注释
score+=1
-一切重新开始
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let box = SKSpriteNode(color: SKColor.red, size: CGSize(width: 50, height: 50))
box.position = location
box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
self.addChild(box)
score += 1 //<----- If to comment this line - everything working again!
print("Nodes: \(self.children.count), score: \(score)")
}
2021-04-03 02:21:00.579404+0100 AP SwiftUI SpriteView iOS14[57663:9610434] Metal API Validation Enabled
Nodes: 1, score: 1
Nodes: 1, score: 2
Nodes: 1, score: 3
Nodes: 1, score: 4