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