【发布时间】:2016-01-02 17:22:59
【问题描述】:
我刚刚更新到 Xcode 7 / Swift 2,我遇到了这个问题,iOS 模拟器中 SpriteKit 中的 x 轴似乎偏离了中心。有人请尝试验证,这很简单。在 Xcode 7 中创建一个新的 SpriteKit 项目,并在 touchesBegan 方法中,在 GameScene.swift 文件中的 let location = touch.locationInNode(self) 下方添加这段代码 print(location)。
然后在 iOS 模拟器(任何设备,尽管我选择 iPhone 4s)中运行它,并在查看输出结果的同时在视图中单击。 Y 轴在底部为零,但 X 轴在左侧似乎在 300 左右,并且随着您向右移动而增加。我正在为此失去理智!
整个touchesBegan 方法将如下所示:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
let location = touch.locationInNode(self)
print(location) // <-- *** ADD THIS LINE ***
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = location
let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
sprite.runAction(SKAction.repeatActionForever(action))
self.addChild(sprite)
}
}
如果你能重现它,请告诉我,为什么会这样!
【问题讨论】:
标签: ios sprite-kit ios-simulator xcode7