【发布时间】:2014-12-27 02:40:25
【问题描述】:
对 SpriteKit 和 iOS 开发来说是全新的。我正在学习一个非常基本的 SpriteKit 教程,并注意到当在与节点。例如:
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
// add a text label at X: 100 and Y: 100
let labelNode = SKLabelNode(text: "X:100 Y:100")
labelNode.position.x = 100
labelNode.position.y = 100
labelNode.fontSize = 20.0
addChild(labelNode)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
// for each touch, print the X and Y positions
for touch: AnyObject in touches {
println("You touched at X: \(touch.locationInView(self.view!).x) and Y: \(touch.locationInView(self.view!).y)")
}
}
}
这会在场景左下角的 X:100 和 Y:100 处添加文本(使用默认的 scene.anchorPoint)。当您触摸时,它会打印您触摸的位置的 X 和 Y。
奇怪的是,当我触摸到标签节点的中心时,我触摸到的1.)节点和2.)的X位置是一致的。但Y不是。节点的 Y 是 100,而触摸的 Y 是 266。请看下面的截图:
谁能解释这是为什么?
【问题讨论】:
标签: ios swift sprite-kit