我想允许用户根据他们在重力文本字段中的输入来更改重力,并将视图控制器的输入传递给SKScene(PhysicsScene),但我不知道如何重新加载场景以便它可以使用自定义用户的重力而不是其默认值。
class SimulationViewController: UIViewController, UITextFieldDelegate {
var sceneNode : PhysicsScene?
@IBOutlet weak var heightTextField: UITextField!
@IBOutlet weak var massTextField: UITextField!
@IBOutlet weak var gravityTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
sceneNode = PhysicsScene(size: view.frame.size)
gravityTextField.delegate = self
if let view = self.view as! SKView? {
view.presentScene(sceneNode)
view.ignoresSiblingOrder = true
view.showsPhysics = true
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField.tag == 0 {
if let text = textField.text {
sceneNode?.customGravity = Double(text)!
print(text)
}
}
return true
}
请帮忙!谢谢!
答案 0 :(得分:1)
您有2个选项,在PhysicsScene类中创建属性
tinymce.get('postfullOnEditPop').setContent(postfull);
或删除自定义重力并直接设置
var customGravity : Double = 0{ didSet { physicsWorld.gravity = {CGPoint(x:0 y:CGFloat(customGravity)}}
我没有XCode可以查看我的错别字,你可能需要打开一些变量