Last active
February 28, 2016 23:22
-
-
Save robertmryan/680113628a06705e17dd to your computer and use it in GitHub Desktop.
Animate spaceship along path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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