为什么ApplyImpulse不能处理physicsBody?

时间:2016-03-30 20:55:37

标签: ios swift sprite-kit physics game-physics

我正在按照教程使用applyImpulse从大炮中射出一个球,但它不能正常工作,只是在我触摸屏幕后才下降到底部?!

    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    let ball:SKSpriteNode = SKScene(fileNamed: "Ball")!.childNodeWithName("ball")! as! SKSpriteNode
    ball.removeFromParent()
    self.addChild(ball)
    ball.zPosition = 0
    ball.position = cannon.position
    let angleInRadians = Float(cannon.zRotation)
    let speed = CGFloat(75.0)
    let vx:CGFloat = CGFloat(cosf(angleInRadians)) * speed
    let vy:CGFloat = CGFloat(sinf(angleInRadians)) * speed
    ball.physicsBody?.applyImpulse(CGVectorMake(vx, vy))
}

0 个答案:

没有答案