This file contains hidden or 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 update(currentTime: CFTimeInterval) { | |
| /* Called before each frame is rendered */ | |
| if lastUpdateTime == 0.0 { | |
| delta = 0 | |
| } else { | |
| delta = currentTime - lastUpdateTime | |
| } | |
| lastUpdateTime = currentTime |
This file contains hidden or 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
| func fireProjectile(delta:CGFloat) { | |
| if timeSinceLastFire >= 0.15 | |
| { | |
| let projectile = SKSpriteNode(imageNamed:"laser1") | |
| projectile.xScale = 0.5 | |
| projectile.yScale = 0.5 | |
| projectile.position = starShip.position | |
| projectile.position.y += starShip.frame.height / 2 | |
| projectile.zPosition = starShip.zPosition + 1 |
This file contains hidden or 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 touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { | |
| /* Called when a touch begins */ | |
| for touch in (touches as! Set<UITouch>) { | |
| let location = touch.locationInNode(self) | |
| moveShipTo(location) | |
| self.fireWeapon = true | |
| } | |
| } |
This file contains hidden or 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
| func moveShipTo(location:CGPoint) | |
| { | |
| starShip.runAction(SKAction.moveTo(location, duration: 0.05)) | |
| } |
This file contains hidden or 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
| var starShip:SKSpriteNode! | |
| var timeSinceLastFire:CGFloat = 0.0 | |
| var fireWeapon:Bool = false | |
| var lastUpdateTime:NSTimeInterval = NSTimeInterval(0) | |
| var delta:NSTimeInterval = NSTimeInterval(0) |
This file contains hidden or 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 { | |
This file contains hidden or 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
| 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") |
This file contains hidden or 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) { |