I'm trying to make circular pulse animation. I used the following code with single view application and it works great, but now I want to assign physics to the circle so I put the same code in sprite kit and its not working. Then I modified the code with SKShapeNode which you can find below. Its not working in sprite kit. Can someone please please help me out with this.
override func drawRect(rect: CGRect) {
let shapeLayer = CAShapeLayer()
let circlePath = UIBezierPath(arcCenter: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2), radius: CGFloat(10), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
shapeLayer.path = circlePath.CGPath
shapeLayer.lineWidth = 1
shapeLayer.strokeColor = UIColor.redColor().CGColor
shapeLayer.fillColor = UIColor.init(red: 247/255, green: 78/255, blue: 0/255, alpha: 0.09).CGColor
layer.addSublayer(shapeLayer)
let animation = CABasicAnimation(keyPath: "path")
animation.duration = 2
animation.repeatCount = 30
animation.toValue = UIBezierPath(arcCenter: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2), radius: CGFloat(1000), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true).CGPath
animation.removedOnCompletion = true
shapeLayer.addAnimation(animation, forKey: nil)
}
Modified Code for SpriteKit
class GameScene: SKScene {
let shapeLayer = CAShapeLayer()
let circlePath = SKShapeNode ()
var path = UIBezierPath ()
override func didMoveToView(view: SKView)
{
/ Setup your scene here */
self.scene!.backgroundColor = UIColor(red: 122/255, green: 167/255, blue: 155/255, alpha: 1)
/
circlePath.path = UIBezierPath(ovalInRect: CGRectMake(0, 0, 20, 20)).CGPath
circlePath.position = CGPoint(x: size.width/2, y: size.height/2)
circlePath.fillColor = UIColor.init(red: 247/255, green: 78/255, blue: 0/255, alpha: 0.09)
circlePath.strokeColor = UIColor.redColor()
circlePath.lineWidth = 1
addChild(circlePath)
shapeLayer.path = circlePath.path
let animation = CABasicAnimation(keyPath: "path")
animation.duration = 2
animation.repeatCount = 30
/
animation.toValue = UIBezierPath(ovalInRect: CGRectMake(0, 0, 1000, 1000)).CGPath
animation.removedOnCompletion = true
shapeLayer.addAnimation(animation, forKey: nil)
}