这个缓动库最初是 buddingmonkey 的 Objective C SpriteKit Easing 库 的 Swift 版本。
这个库在 Apple 的 SpriteKit 框架中可用的基础上增加了基本的缓动方程。
Sprite Kit Easing 以 SKActions 形式提供以下标准缓动方程。
使用 SKEase 方法来插值 SKNode 的属性,例如
- 移动
- 缩放
- scaleX
- scaleY
- 旋转
- 淡入
- tweenLabelColor
- tweenShapeFillColor
如果您想插值一个变量,请使用
- createPointTween
- createFloatTween
- createColorTween
SKEase 函数返回一个执行缓动的 SKAction。然后,您可以在 SpriteKit 中以相同的方式运行 SKAction,就像其他任何 SKAction 一样。
//eg an SKLabelNode(which extends SKNode) flies in from the right with an elastic tween:
//first create an SKNode, let's create a label node
let titleLabel = SKLabelNode(fontNamed:"Avenir-Light")
titleLabel.text = "Hello world"
titleLabel.fontSize = 65
titleLabel.fontColor = UIColor.white
titleLabel.position = CGPoint(x:self.frame.midX, y:self.frame.midY)
self.addChild(titleLabel)
//perform elastic ease
titleLabel.run(SKEase.move(easeFunction: .curveTypeElastic,
easeType: .easeTypeOut,
time: 2,
from: CGPoint(x: frame.width+titleLabel.frame.width/2, y: titleLabel.position.y),
to:CGPoint(x: -titleLabel.frame.width/2, y: titleLabel.position.y)))
安装
通过 CocoaPods
SpriteKitEasingSwift 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中。
pod 'SpriteKitEasingSwift'
要运行示例项目,先克隆仓库,然后从 Example 目录运行 pod install
。
别忘了在需要使用 Pod 的地方导入它
import SpriteKitEasingSwift
通过 Github
从 Github 克隆项目(https://github.com/craiggrummitt/SpriteKitEasingSwift)。您在那儿也可以找到一个示例项目。要使用框架,将 SpriteKitEasingSwift/Classes 文件夹拖到您的项目中。
作者
再次感谢 SpriteKitEasing 和 AHEasing 以及缓动领域的传奇人物 Robert Penner。
许可协议
SpriteKitEasingSwift 可在 MIT 许可协议下使用。查看 LICENSE 文件获取更多信息。