Sprite Kit Swift - 字符加速和减速

时间:2017-07-31 12:14:56

标签: swift3 sprite-kit skphysicsbody skaction

我是Swift Sprite Kit的新手,我想移动一个节点,启动速度= 0,直到按下按钮2秒钟的最大速度,并以-5速度减速,直到按钮释放时的最小速度。我做过这样的事情:

func moving(force : CGFloat){

    self.player.physicsBody?.applyImpulse(CGVector(dx:force*cos(player.zRotation + 1.57079633), dy: initialforce*sin(player.zRotation + 1.57079633)))
}

触控功能:

let timerAction = SKAction.wait(forDuration: 0.05)

     let update = SKAction.run({
          if(self.initialforce < Constants.maximumMoveForce){
               self.force += 1.0
             }else{

                    self.moving(force: Constants.maximumMoveForce)

                    self.force = Constants.maximumMoveForce

                }
            })
      let sequence = SKAction.sequence([timerAction, update])
      let repeats = SKAction.repeatForever(sequence)
      self.run(repeats, withKey:"repeatAction")

我怎么在touchEnd减速呢?还是我做错了?需要帮助。

0 个答案:

没有答案