Last active
August 29, 2015 14:10
-
-
Save Bashta/b5bdcd941c50250a5e2d to your computer and use it in GitHub Desktop.
GameScene
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
import SpriteKit | |
protocol GameSceneDelegate { | |
func gameOver() | |
} | |
class GameScene: SKScene { | |
var gameSceneDelegate: GameSceneDelegate? | |
var health: Int = 10 | |
var helthLabel = SKLabelNode(fontNamed: "Chalkduster") | |
override func didMoveToView(view: SKView) { | |
/* Setup your scene here */ | |
helthLabel.text = "GameScene"; | |
helthLabel.fontSize = 20; | |
helthLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame)); | |
self.addChild(helthLabel) | |
} | |
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { | |
/* Called when a touch begins */ | |
for touch: AnyObject in touches { | |
let location = touch.locationInNode(self) | |
health-- | |
helthLabel.text = "Your health is \(health)" | |
if health <= 0 { | |
self.gameSceneDelegate?.gameOver() | |
} | |
} | |
} | |
override init(size: CGSize) { | |
super.init(size: size) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
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