我想检测在屏幕的某些区域中进行的触摸,并为已触摸的每个区域关联确定的动作。
类似的东西:
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 :(得分:0)
您必须创建一些代表您所在区域的SKSpriteNodes
。之后,您可以检查用户是否按下了指定的节点。
首先,您必须设置SKSpritenodes的名称:
yourNode.name =“fire”
之后,如果您的节点被触摸,您可以检查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
}