我目前在同一个SKScene上有多个球。我处理GameScene中的所有触摸和手势。下面是我用来检测哪个节点被触摸的代码,它起作用。
我不确定的是,由于在实际设备上使用touchesMoved时总是有一些touchesMoved,因此是否有可能多个节点同时接收拍子?如果是这样,我显然将需要以不同的方式编写我的代码。
@objc func tappedView(_ sender:UITapGestureRecognizer) {
if sender.state == .ended{
let point : CGPoint = sender.location(in: self.view)
var post = sender.location(in: sender.view)
post = self.convertPoint(fromView: post)
if let touchNode = self.atPoint(post) as? MyBall{
//the declaration below is just so I have somewhere to stop in the debugger
var x = 1
}
}
}
用于nodes(at:)
在一个点上获取多个节点。
@objc func tappedView(_ sender:UITapGestureRecognizer) {
if sender.state == .ended{
let point : CGPoint = sender.location(in: self.view)
var post = sender.location(in: sender.view)
post = self.convertPoint(fromView: post)
for touchNode in self.nodes(at:post){
//the declaration below is just so I have somewhere to stop in the debugger
var x = 1
}
}
}
https://developer.apple.com/documentation/spritekit/sknode/1483072-nodes
抱歉,如果您看了看一下相关的文档,就会习惯于老套
谢谢,实际的语法竟然是:“对于self.nodes中的touchNode(at:post)”
是的,我已经更新了答案以反映出来
是的我知道。谢谢你 我发誓要谢谢你的名字。实际上,我现在刚回来解释什么音乐看起来绝对是懒惰。我不是阅读困难的人,但有一些使我不好的读者。不只是懒惰。