Skip to content

Instantly share code, notes, and snippets.

@Bashta
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bashta/b5bdcd941c50250a5e2d to your computer and use it in GitHub Desktop.
Save Bashta/b5bdcd941c50250a5e2d to your computer and use it in GitHub Desktop.
GameScene
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