为什么这不会产生动画?

时间:2014-10-28 17:00:42

标签: ios swift sprite-kit

我正在使用SpriteKit为角色跳跃设置动画。

我知道正确的代码是什么,但我不知道为什么我以前的代码不正确。

正确:

let actionMove = SKAction.moveTo(CGPoint(x: size.width * 0.1, y: size.height * 0.85), duration: 0.3)
let actionFall = SKAction.moveTo(CGPoint(x: size.width * 0.1, y: size.height * 0.3), duration: 0.3)
actionMove.timingMode = SKActionTimingMode.EaseIn
actionFall.timingMode = SKActionTimingMode.EaseOut

if CACurrentMediaTime() - time > 0.7 {
  player.runAction(SKAction.sequence([actionMove, actionFall]))
  time = CACurrentMediaTime()
}

不正确:

func jump() {
  let actionMove = SKAction.moveTo(CGPoint(x: size.width * 0.1, y: size.height * 0.85), duration: 0.3)
  let actionFall = SKAction.moveTo(CGPoint(x: size.width * 0.1, y: size.height * 0.3), duration: 0.3)
  actionMove.timingMode = SKActionTimingMode.EaseIn
  actionFall.timingMode = SKActionTimingMode.EaseOut
  player.runAction(SKAction.sequence([actionMove, actionFall]))
}
if (player.position.y == size.height * 0.3){
  jump();
}

在错误的代码中,当用户点击屏幕时,角色不会跳跃 - 角色保持在高度0.3。

0 个答案:

没有答案