Last active
August 29, 2015 14:19
-
-
Save efrenjgb/c6df3ba92e04cabb76e4 to your computer and use it in GitHub Desktop.
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
// | |
// 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