Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 斯普林泰诺链_Swift_Xcode_Sprite Kit_Skspritenode_Sknode - Fatal编程技术网

Swift 斯普林泰诺链

Swift 斯普林泰诺链,swift,xcode,sprite-kit,skspritenode,sknode,Swift,Xcode,Sprite Kit,Skspritenode,Sknode,我想让“aware”SKSpriteNode知道触摸在节点外部(例如更改颜色) 如果可能的话,我想使用tuochesMoved(节点外) 我不想用任何其他方式把它们联系起来。 那些精灵应该是独立的 怎么做 谢谢显然,您可以实施touchsbegind方法来处理触摸事件: override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { if let touch = touches.first

我想让“aware”SKSpriteNode知道触摸在节点外部(例如更改颜色)

如果可能的话,我想使用tuochesMoved(节点外)

我不想用任何其他方式把它们联系起来。 那些精灵应该是独立的

怎么做


谢谢

显然,您可以实施
touchsbegind
方法来处理触摸事件:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = touches.first {
        // ...
    }
    super.touchesBegan(touches, with: event)
}

可能有几种方法可以做到这一点,但我立刻想到的是Swift的didSet和willSet属性观察家。您可以在触摸对象内部创建一个布尔变量,该变量本身有一个didSet或willSet(一个函数,在发生更改时激活,您将在触摸对象的ToucheSBegind方法中进行更改),这可以告诉其他精灵有关触摸的信息。但它需要有它的细节,所以这有点混乱。。。我不是专家。很抱歉,我想获取接触移动到节点外部的信息。你能帮我吗?谢谢抱歉,我想获取touchesMove在节点外部移动的信息。你能帮我吗?谢谢你应该添加一个新的问题,之后,给我发送新的链接。我很乐意帮助您。
对于
touchscancelled
的第一个参数至关重要,谢谢!
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesCancelled(_ touches: Set<UITouch>?, with event: UIEvent?) {
// Don't forget to add "?" after Set<UITouch>
}
yourSprite.userData = NSMutableDictionary()
yourSprite.userData?.setValue(SKColor.blue, forKeyPath: "currentColor")
yourSprite.userData?.setValue(true, forKeyPath: "selected")