我正在做一个非常简单的太空游戏;我似乎无法使最后一行生效。理想情况下,我希望在触摸屏幕时使空间向上移动。这是我的代码:

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)


有谁知道如何做到这一点?

最佳答案

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中将触摸更改为使用_

10-06 11:18