切割时如何为整个屏幕制作动画?

时间:2016-06-26 00:25:50

标签: swift sprite-kit

当敌人与玩家对战时,我想让屏幕震动。我一直在寻找一个可行的答案,但我找不到任何东西。如果有人可以帮助我,谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个

func shakeFrame(scene: SKScene) {

    let animation: CABasicAnimation = CABasicAnimation(keyPath: "position")
    animation.duration = 0.05
    animation.repeatCount = 4
    animation.autoreverses = true
    animation.fromValue = NSValue(CGPoint: CGPointMake(scene.view!.center.x - 4.0, scene.view!.center.y))
    animation.toValue = NSValue(CGPoint: CGPointMake(scene.view!.center.x + 4.0, scene.view!.center.y))
    scene.view!.layer.addAnimation(animation, forKey: "position")
}

在你的情况下试试这个

func shakeFrame(scene: SKScene) {

    let animation: CABasicAnimation = CABasicAnimation(keyPath: "position")
    animation.duration = 0.05
    animation.repeatCount = 4
    animation.autoreverses = true
    animation.fromValue = NSValue(CGPoint: CGPointMake(scene.view!.center.x - 4.0, scene.view!.center.y))
    animation.toValue = NSValue(CGPoint: CGPointMake(scene.view!.center.x + 4.0, scene.view!.center.y))
    scene.view!.layer.addAnimation(animation, forKey: "position")
}

if hits < 2 && circuloPrincipal.color != enemigo.color {
    shakeFrame()
}