Skip to content

Instantly share code, notes, and snippets.

@veeneck
veeneck / enumerate.swift
Created June 17, 2014 19:18
Swift Enumerate
self.enumerateChildNodesWithName("PurchaseMenu", usingBlock:
{ (node: SKNode!, stop: CMutablePointer<ObjCBool>) in
node.removeFromParent()
}
)
@veeneck
veeneck / casting.swift
Last active August 29, 2015 14:02
Swift Casting
scene.enumerateChildNodesWithName("flag") {
node, stop in
let realNode = node as Flag
realNode.hidePurchaseMenus()
}
@veeneck
veeneck / param.swift
Last active August 29, 2015 14:02
Swift Casting in Callback Parameter
// How do you cast SKNode to Flag : SKNode in parameter definition?
scene.enumerateChildNodesWithName("flag") {
node as Flag, stop in
node.methodAvailableToFlagObject()
}
// I'm trying to avoid having to do this:
scene.enumerateChildNodesWithName("flag") {
@veeneck
veeneck / callbackshort.swift
Created June 17, 2014 20:57
Callback Shortcode
scene.enumerateChildNodesWithName("PurchaseMenu") {
node, stop in
node.removeFromParent()
}
@veeneck
veeneck / plist.swift
Created June 17, 2014 21:19
Load pList in Swift
let path = NSBundle.mainBundle().bundlePath + "/FlagProgression.pList"
let pListData = NSDictionary(contentsOfFile:path)
let flagData = pListData[self.category.toRaw()] as NSArray
return flagData.objectAtIndex(self.currentLevel) as Dictionary<String, String>[]
@veeneck
veeneck / difftype.swift
Created June 17, 2014 21:31
Loop different data types in Swift
for item : NSDictionary! in flagData {
let flagToPlace = Flag(category: item["Type"].integerValue)
}
@veeneck
veeneck / allinit.swift
Created June 17, 2014 21:46
Define Init's in Swift
init(category:Int) {
super.init(texture: FlagSingleton.textures[category])
}
init(texture:SKTexture, color:SKColor, size:CGSize) {
super.init(texture:texture, color:color, size:size)
}
@veeneck
veeneck / maininit.swift
Created June 17, 2014 21:48
One Init in Swift
init(category:Int) {
super.init(texture: FlagSingleton.textures[category], color:SKColor.whiteColor(), size:FlagSingleton.textures[category].size())
}
@veeneck
veeneck / Squad.swift
Last active August 29, 2015 14:06
The squad class that holds our units.
import SpriteKit
import Foundation
class Squad : SKNode {
// Handle on all units in the squad.
var units : Array<CharacterNode> = []
// Current formation technique
var formation : Formation?
@veeneck
veeneck / Formation.swift
Created September 8, 2014 17:00
Formation to describe how the squad should arrange themselves.
import SpriteKit
class Formation {
// The vectors for a 3x3 formation.
var positions : Array<CGVector> = [
CGVectorMake(0, 0),
CGVectorMake(-64, 0),
CGVectorMake(64, 0),
CGVectorMake(-64, 64),