Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Last active February 28, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertmryan/680113628a06705e17dd to your computer and use it in GitHub Desktop.
Save robertmryan/680113628a06705e17dd to your computer and use it in GitHub Desktop.
Animate spaceship along path
override func didMoveToView(view: SKView) {
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.25
sprite.yScale = 0.25
addChild(sprite)
let origin = view.convertPoint(view.bounds.origin, toScene: self)
let lowerRight = view.convertPoint(CGPoint(x: CGRectGetMaxX(view.bounds), y:CGRectGetMaxY(view.bounds)), toScene: self)
let visibleFrame = CGRect(x: origin.x, y: origin.y, width: lowerRight.x - origin.x, height: lowerRight.y - origin.y)
let path = sinePathInRect(visibleFrame)
let action = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, duration: 10)
sprite.runAction(action)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment