Skip to content

Instantly share code, notes, and snippets.

override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
if lastUpdateTime == 0.0 {
delta = 0
} else {
delta = currentTime - lastUpdateTime
}
lastUpdateTime = currentTime
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
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
}
}
func moveShipTo(location:CGPoint)
{
starShip.runAction(SKAction.moveTo(location, duration: 0.05))
}
var starShip:SKSpriteNode!
var timeSinceLastFire:CGFloat = 0.0
var fireWeapon:Bool = false
var lastUpdateTime:NSTimeInterval = NSTimeInterval(0)
var delta:NSTimeInterval = NSTimeInterval(0)
//
// GameScene.swift
// spaceshooter
//
//
import SpriteKit
class GameScene: SKScene {
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")
//
// GameScene.swift
// spaceshooter
//
//
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {