2015-01-30 2 views
0

화면의 특정 영역에서 이루어진 터치를 감지하고 터치 된 각 영역에 대해 결정된 동작을 연관 시키려고합니다. 이 같은특정 위치에서 신속한 핸들 터치 - GameScene 클래스

뭔가 :

3 areas that are touchable, and each one has a different action

내 코드는 지금까지 있습니다 :

일반적으로
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { 
    /* Called when a touch begins */ 

    for touch: AnyObject in touches { 
     let location = touch.locationInNode(self) 
     attackInTouch(heroAtlas) //function that gives me the animation of "attack" 

    } 
} 

영웅이 실행되고, 모든 터치 그는 "공격"(에 애니메이션이 표시됩니다)하지만 터치 위치를 처리하기 위해 영역을 선언하고 해당 동작을 활성화하려면

도움을 주시면 감사하겠습니다.

답변

0

지역을 나타내는 SKSpriteNodes을 만들어야합니다. 그런 다음 사용자가 지정된 노드를 눌렀는지 확인할 수 있습니다.

먼저 당신은 당신의 SKSpritenodes의 이름을 설정해야합니다 :

yourNode.name = "화재"노드 터치 한 경우 당신은 당신의 touchesBegan 방법으로 확인할 수 있습니다 그 후

:

let location = touch.locationInNode(self) 
let node:SKNode = self.nodeAtPoint(location) 

if(node.name == "specialNode"){ 
    //do something with your specialnode 
}else if(node.name == "fire"){ 
    //do something with your fire-node 
}