在我的主应用程序中,我尝试使用 3D 触摸来激活子弹发射,但结果似乎非常不一致,而且它并不总是给我写入结果。当我使用这段代码时,我的 iPhone 6S 也崩溃了,这是我用于测试的代码。
for touch in touches {
let location = touch.locationInNode(self)
var force = touch.force * 10
var maxForce = touch.maximumPossibleForce
print ("The force is")
print (maxForce*4)
print (force*10000000)
if force != 0{
myLabel.text = "Force"
myLabel.fontSize = 45
myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
self.addChild(myLabel)
myLabel.zPosition = 100000
}
else {
myLabel.removeFromParent()
}
最佳答案
我猜它会崩溃,因为您多次向父级添加标签(您的 if 条件被破坏,无论您调用什么函数,(touchesBegan
,touchesMoved
,touchesEnded
) 只有一个条件永远为真,在 touchesBegan
和 touchesMoved
中,你的力量永远 > 0,在你的 touchEnded
中,你的力应该是 0。(我假设这个代码是你的 touchMoved
)相反,在你的 viewDidLoad 代码中添加你的标签,并使用.hidden 字段显示/隐藏你的移动标签。(确保在 touchesEnded
上隐藏它)
关于ios - 在 Sprite Kit 中使用 3D touch 测量压力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36245081/