ノードにジェスチャを追加することはありません。
ジェスチャーは、ジェスチャーを認識できるものにのみ追加できます。 UIKitので
、これらはWatchkitでUIViews
あるジェスチャが開始したとき、これらはWKInterfaces
ている今、あなたはWatchkitで何をしたいのか、あなたはノードに
に触れているかどうかを検出、ありますこれを行うには、locationinObject
で位置を取得し、シーンでシーン座標系に変換することによってWatchkitでこれを行うことができます。
extension WKGestureRecognizer {
var position : CGPoint
{
get
{
let location = locationInObject()
let bounds = objectBounds()
let dWidth = self.scene.size.width/bounds.size.width
let dHeight = self.scene.size.height/bounds.size.height
let x = (location.x * dWidth) - scene.width * scene.anchorPoint.x)
let y = (bounds.maxY - location.y) * dHeight - (scene.height * scene.anchorPoint.y)
return CGPoint(x:x, y:y)
}
}
}
これは、インターフェイスであなたの位置を取得し、次にy軸を反転させてシーンに変換し、シーンの幅とインターフェイスの幅の差を調整することです。
今これを使用するには、単にあなたが、認識方法の中にある場合、それを呼び出すと、あなたが接触しているノードが自分のノードであるかどうかをチェック
func didPan(_ recognizer: WKPanGestureRecognizer) {
switch(recognizer.state)
{
case .began:
let scenePosition = recognizer.position
let node = scene.atPoint(scenePosition)
guard let node = shapeNode else {return}
//allow pan, so make a note or something
case //do other cases here
}
}