Skip to content

Instantly share code, notes, and snippets.

@efrenjgb
Last active August 29, 2015 14:19
Show Gist options
  • Save efrenjgb/c6df3ba92e04cabb76e4 to your computer and use it in GitHub Desktop.
Save efrenjgb/c6df3ba92e04cabb76e4 to your computer and use it in GitHub Desktop.
//
// GameScene.swift
// spaceshooter
//
//
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
self.backgroundColor = SKColor.blackColor()
let starFieldEmmiter = SKEmitterNode(fileNamed: "StarField.sks")
starFieldEmmiter.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame))
starFieldEmmiter.zPosition = -20
starFieldEmmiter.advanceSimulationTime(NSTimeInterval(starFieldEmmiter.particleLifetime))
self.addChild(starFieldEmmiter)
let starship = SKSpriteNode(imageNamed:"Spaceship")
starship.xScale = 0.2
starship.yScale = 0.2
starship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame) + 100)
self.addChild(starship)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = location
let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
sprite.runAction(SKAction.repeatActionForever(action))
self.addChild(sprite)
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment