Ios 斯威夫特斯皮特基特计数触摸
我试图在一个节点上执行多个操作 因此,例如,在第一次触摸该节点时,第一个操作应该运行。在第二次触摸时:第二个动作应该运行 下面是一个使用touchs.count的代码不起作用的示例Ios 斯威夫特斯皮特基特计数触摸,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我试图在一个节点上执行多个操作 因此,例如,在第一次触摸该节点时,第一个操作应该运行。在第二次触摸时:第二个动作应该运行 下面是一个使用touchs.count的代码不起作用的示例 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { for touch: AnyObject in touches { let location = touch.locatio
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node == myNode {
if touches.count == 1 {
action1()
}
if touches.count == 2 {
action2()
}
if touches.count == 3 {
action3()
}
}
}
}
override func touchsbegined(touchs:Set,withEvent-event:UIEvent){
用于触摸:触摸中的任何对象{
let location=touch.locationInNode(自)
设node=self.nodeAtPoint(位置)
如果node==myNode{
if.count==1{
行动1()
}
if.count==2{
行动2()
}
if.count==3{
行动3()
}
}
}
}
我想您应该使用touchs.tapCount而不是count。这会检测您正在进行的抽头,并应记录1、2和3(抽头很快,因此您必须快速抽头)
编辑:你是指有人轻触屏幕多少次,还是指一次有多少手指在屏幕上 我想你应该使用touch.tapCount而不是count。这会检测您正在进行的抽头,并应记录1、2和3(抽头很快,因此您必须快速抽头)
编辑:你是指有人轻触屏幕多少次,还是指一次有多少手指在屏幕上 您需要一个成员变量来跟踪自应用启动以来的触摸次数。方法touchs.count不是累积的
var cumulativeNumberOfTouches = 0
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node == myNode {
cumulativeNumberOfTouches += 1
switch cumulativeNumberOfTouches {
case 1:
action1()
case 2:
action2()
case 3:
action3()
default:
/* do something or nothing or whatever */
println("\(cumulativeNumberOfTouches) touches")
}
}
}
}
var cumulativeEnumberOfTouches=0
覆盖func touchesBegined(触摸:设置,withEvent事件:UIEvent){
用于触摸:触摸中的任何对象{
let location=touch.locationInNode(自)
设node=self.nodeAtPoint(位置)
如果node==myNode{
累计EnumberOfTouches+=1
切换累积性Enumberoftouchs{
案例1:
行动1()
案例2:
行动2()
案例3:
行动3()
违约:
/*做点什么,什么也不做,或者随便什么*/
println(“\(累积EnumberOfTouchs)触摸”)
}
}
}
}
您需要一个成员变量来跟踪应用程序启动后的触摸次数。方法touchs.count不是累积的
var cumulativeNumberOfTouches = 0
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node == myNode {
cumulativeNumberOfTouches += 1
switch cumulativeNumberOfTouches {
case 1:
action1()
case 2:
action2()
case 3:
action3()
default:
/* do something or nothing or whatever */
println("\(cumulativeNumberOfTouches) touches")
}
}
}
}
var cumulativeEnumberOfTouches=0
覆盖func touchesBegined(触摸:设置,withEvent事件:UIEvent){
用于触摸:触摸中的任何对象{
let location=touch.locationInNode(自)
设node=self.nodeAtPoint(位置)
如果node==myNode{
累计EnumberOfTouches+=1
切换累积性Enumberoftouchs{
案例1:
行动1()
案例2:
行动2()
案例3:
行动3()
违约:
/*做点什么,什么也不做,或者随便什么*/
println(“\(累积EnumberOfTouchs)触摸”)
}
}
}
}
tapCount也不是解决方案。这计算了一个“触摸阶段”中的触摸次数。我正在寻找一个计算自应用程序启动以来总触摸次数的方法。tapCount也不是解决方案。这计算了一个“触摸阶段”的次数。我正在寻找一个可以计算自应用程序启动以来总触摸次数的东西。