2014-10-12 3 views

답변

0

당신은

당신은 위치를 얻을 수 있습니다 SKNode의 위치로 터치의 위치를 ​​비교해야합니다 locationInNode()를 사용하여 다음 방법 중 하나에서 터치 할 수 있습니다.

  • touchesBegan()
  • 있는 touchesMoved()
  • touchesEnded()
+1

좀 더 자세히 pls – user3138007

1

애플의 SceneKitVehicle 데모를 검사합니다. 누군가 친절하게 ported it to Swift입니다.

원하는 코드는 GameView.swift 파일에 있습니다. GameView에서는 touchesBegan을 재정의합니다. Swift 2.1에 대한 나의 버전은 다음과 같습니다.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    guard let scene = self.overlaySKScene else { 
     return 
    } 

    let touch = touches.first! 
    let viewTouchLocation = touch.locationInView(self) 
    let sceneTouchPoint = scene .convertPointFromView(viewTouchLocation) 
    let touchedNode = scene.nodeAtPoint(sceneTouchPoint) 

    if (touchedNode.name == "Play") { 
     print("play") 
    } 
} 

분명하지 않은 경우; GameView는 스토리 보드를 통해 앱의보기 클래스로 설정됩니다.

관련 문제