gpt4 book ai didi

ios - touch.locationInView 没有像我想的那样工作

转载 作者:行者123 更新时间:2023-11-28 13:12:17 24 4
gpt4 key购买 nike

我试图做到这一点,以便在我触摸场景中的节点时我的游戏能够识别,除非我使用下面的代码,我认为这完全符合我的要求,我的应用程序无法正确识别节点的位置.

我在屏幕的其余部分周围单击,打印出我正在触摸的节点的名称,事实证明我的应用程序认为节点的位置与实际位置不同(x 值是正确的 y值(value)非常低)

你看到什么地方不对了吗?

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */

for touch in (touches as! Set<UITouch>) {
var TouchlocationEnd = touch.locationInView(self.view!)
let touchedNode = self.nodeAtPoint(TouchlocationEnd)

var name = touchedNode.name

println(name)

if name == "start"{
var scene = PlayScene(size: self.view!.bounds.size)
scene.scaleMode = .AspectFill
self.view!.presentScene(scene)
}
}
}

最佳答案

根据 Apple 的文档,nodeAtPoint() 函数采用“节点坐标系中的一个点”。但是您找到的点是 View 中的位置,它不一定与您在此处子类化的任何节点位于同一坐标系中。

换句话说,我猜测“self.view”的坐标系与“self”的坐标系不同。尝试这样的事情(未经测试):

let touchPoint = touch.locationInNode( self )
let touchedNode = self.nodeAtPoint( touchPoint )

关于ios - touch.locationInView 没有像我想的那样工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30851229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com