如何使箭头像this video中那样摆动?
到目前为止,我可以像this video一样来回旋转节点,使用didMove(to:)
中SKScene
中的以下代码:
// Ball
let ballNode = SKSpriteNode(imageNamed: "Ball")
let offsetFromCorner: CGFloat = 20
ballNode.position = CGPoint(x: frame.minX + ballNode.size.width / 2 + offsetFromCorner, y: frame.minY + ballNode.size.height / 2 + offsetFromCorner)
addChild(ballNode)
/* ... */
// Aim arrow
let aimArrowNode = SKSpriteNode(imageNamed: "AimArrow")
aimArrowNode.position.y += aimArrowNode.size.height / 2
ballNode.addChild(aimArrowNode)
ballNode.zRotation = -.pi / 18 * 8
let rotateUp = SKAction.rotate(toAngle: -.pi / 18, duration: 1)
let rotateDown = SKAction.rotate(toAngle: -.pi / 18 * 8, duration: 1)
let combinedActions = SKAction.sequence([rotateUp, rotateDown])
ballNode.run(SKAction.repeatForever(combinedActions))
但是,我希望箭头越靠近边缘,它看起来就越“慢”。我该如何实现?
如有任何疑问,请询问!
答案 0 :(得分:0)
幸运的是,答案实际上内置于SKAction
中。
在创建操作后只需添加以下内容:
rotateUp.timingMode = .easeInEaseOut
rotateDown.timingMode = .easeInEaseOut
现在您可以得到我一直在寻找的效果! :)