ios - 如何在 Swift 2.0 中将基本向量应用于物理体

标签 ios swift sprite physics

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

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 中将 Touch 中的 touch 更改为使用 _

关于ios - 如何在 Swift 2.0 中将基本向量应用于物理体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31542271/

相关文章:

ios - 如何在 Swift 中使用协议(protocol)公开 Objective-C 对象的私有(private)类方法?

CSS3 动画不适用于任何浏览器

ios - 在 iOS 中实现收藏夹按钮

ios - 为什么对象没有添加到我的数组中?

ios - ios objective c中的内存管理

ios - Swift 3 遍历类数组

swift - Swift 中的类方法和实例方法有什么区别?

java - 为什么我不能删除我的雪碧

java - LWJGL - 如果我使用 VBO,我可以对单独的纹理做些什么?

iphone - 如何限制 NSFetchRequest 的结果数?