所以我需要在场景中对SKSpriteNode实现视差效果。我以前在单视图应用程序中使用UIImageViews,但现在我面临以下问题:SKSpriteNodes没有属性addMotionEffect。我一直在寻找,似乎找不到类似的东西。我用于单一视图应用的代码:
@IBOutlet weak var x: UIImageView!
override func viewDidLoad() {
applyMotionEffect(toView: x)
}
func applyMotionEffect(toView view:UIView) {
let xMotion = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
xMotion.minimumRelativeValue = -10
xMotion.maximumRelativeValue = 10
let yMotion = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
yMotion.minimumRelativeValue = -10
yMotion.maximumRelativeValue = 10
let group = UIMotionEffectGroup()
group.motionEffects = [xMotion, yMotion]
view.addMotionEffect(group)
}
我需要实现这样的目标:
spriteNode.addMotionEffect(group)