在iOS中的一个圆圈的动画

时间:2016-03-26 18:05:58

标签: ios swift animation sprite-kit

我正在学习如何使用SpriteKit,并希望有一个圆圈:

  • 平稳地生长和收缩
  • 带有颜色的脉冲
  • 显示边缘清晰

到目前为止,我已经提出以下代码:

import SpriteKit

class GameScene: SKScene {

    override func didMoveToView(view: SKView) {
        addCircle()
    }

    func addCircle(){
        let circle = SKShapeNode(circleOfRadius: 50 ) // Size of Circle
        circle.position = CGPointMake(frame.midX, frame.midY)  //Middle of Screen
        circle.glowWidth = 0.0 // No border
        circle.fillColor = SKColor.yellowColor() // Start as yellow
        let actualDuration = 1 // Animate for 1s
        // Basic actions for grow, shrink, colour up, colour down
        let actionGrow = SKAction.scaleTo(CGFloat(2), duration: NSTimeInterval(actualDuration))
        actionGrow.timingMode = SKActionTimingMode.EaseInEaseOut
        let actionShrink = SKAction.scaleTo(CGFloat(0.5), duration: NSTimeInterval(actualDuration))
        actionShrink.timingMode = SKActionTimingMode.EaseInEaseOut
        let actionColorUp = SKAction.colorizeWithColor(UIColor.redColor(), colorBlendFactor: 1.0, duration: NSTimeInterval(actualDuration))
        let actionColorDown = SKAction.colorizeWithColor(UIColor.redColor(), colorBlendFactor: 0.0, duration: NSTimeInterval(actualDuration))
        // Combine the actions
        let actionGrowWithColor = SKAction.group([actionGrow,actionColorUp])
        let actionShrinkWithColor = SKAction.group([actionShrink,actionColorDown])
        // Run and repeat
        circle.runAction(SKAction.repeatActionForever(SKAction.sequence([actionGrowWithColor,actionShrinkWithColor])))
        // Add the circle
        self.addChild(circle)

    }
}

我的三个标准中的第一个符合,但其他两个不符合。

  • 由于SKShapeNode不是矢量,因此随着它的增长,边缘不清晰。是否有更好的方法来绘制圆圈,或者我应该从一个足够大的圆圈开始?
  • colorizeWithColor部分似乎没有任何效果吗?

非常感谢提前!

0 个答案:

没有答案