Spritekit:使用 运行 atlas 和移动节点的动画节点

Spritekit: Animate node with running atlas and move node

我想使用 .atlas 将角色动画化为 运行 并同时在屏幕上移动角色。 我能够使用 atlas 模拟 运行 但不知道如何同时移动它。 现在我用这个:

let animation = SKAction.animateWithTextures(frames, timePerFrame: 0.2)  

monsterNode.runAction((animation)).

例如,您可以对节点的 physicsBody 施加力。这对于平台游戏来说很棒,因为障碍物和地标会减慢角色的速度,使其更逼真。

let force = CGVector(dx: 9000, dy: 0)
self.physicsBody?.applyForce(force)

对于 space 赛车手或其他更简单的机芯,您可以简单地对其应用 velocity

self.physicsBody?.velocity = CGVector(dx: 100, dy:10)

有关更多信息,请参阅 SKPhysicsBody reference

更新: 对于非常简单的动作,可以使用SKAction的moveBy and moveTo methods and group动作和动画。

let vector = CGVector(dx:100, dy: 10)
let moveAction = SKAction.move(by: vector, duration: 1)
yourNode.run(SKAction.group([moveAction, animationAction])