我正在做一个非常简单的太空游戏;我似乎无法让最后一行工作。理想情况下,我希望在触摸屏幕时让空间向上移动。这是我的代码:
func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
touch.locationInNode(self)
spacey.physicsBody!.velocity = (CGVectorMake(0, 0))
spacey.physicsBody!.applyImpulse(0, atPoint: 25)
有没有人知道如何做到这一点?
答案 0 :(得分:0)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
_ = touch.locationInNode(self)
spacey.physicsBody!.velocity = CGVectorMake(0, 0)
spacey.physicsBody!.applyImpulse(CGVectorMake(0, 25))
解决方案是在触摸中改变触摸以在swift 2.0中使用_