Skip to content

Instantly share code, notes, and snippets.

@veeneck
veeneck / cgpoint.m
Created April 12, 2014 18:07
Current Point in a CGPath
// For example, if you ArcToPoint and want to find out where the arc ends
// so that you can begin the next path, use this
CGPoint current = CGPathGetCurrentPoint(pathing);
//And if you want to log that
NSLog(@"%@", NSStringFromCGPoint(current);
@veeneck
veeneck / layers.m
Last active August 29, 2015 14:00
zPosition World Layers
/* The layers in a scene. */
typedef enum : uint8_t {
WorldLayerGround = 0,
WorldLayerBelowCharacter,
WorldLayerCharacter,
WorldLayerAboveCharacter,
WorldLayerTop,
kWorldLayerCount
} WorldLayer;
@veeneck
veeneck / zposition.m
Last active August 29, 2015 14:00
Update zPosition
- (void)update:(NSTimeInterval)currentTime
{
[characterLayer enumerateChildNodesWithName:@"soldier" usingBlock: ^(SKNode *node, BOOL *stop) {
[(Soldier*)node updatePosition];
}];
}
// And then in the Soldier class
- (void)updatePosition {
self.zPosition = 10000 - self.position.y;
@veeneck
veeneck / container.m
Last active August 29, 2015 14:00
Pointer to Container
class Formation {
array soliders = []
function addSoldier(soldier) {
soldier.formation = self; // This is the line in question
self.soldiers.push(soldier);
}
}
@veeneck
veeneck / lightsource.m
Created June 3, 2014 01:41
Adding light to Sprite Kit
SKLightNode* sun = [[SKLightNode alloc] init];
sun.position = CGPointMake(500,500);
// These 3 lines are critical
sun.enabled = YES; // Toggles the light source on and off.
sun.categoryBitMask = 1; // Defines the category of this light source.
[your_scene addChild:sun]; // Must be added to the world to work.
@veeneck
veeneck / lightmasks.m
Created June 3, 2014 01:45
The different masks for lights
node.shadowCastBitMask = 1;
node.lightingBitMask = 1;
node.shadowedBitMask = 1;
@veeneck
veeneck / viewcontroller.swift
Created June 17, 2014 15:34
Swift view Controller
if let scene = Foothills.unarchiveFromFile("Foothills") as? SKScene {
Foothills.loadSceneAssetsWithCompletionHandler({
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
@veeneck
veeneck / dispatch.swift
Created June 17, 2014 15:39
Swift Dispatch Async
class func loadSceneAssetsWithCompletionHandler(handler:()->()) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
MySprite.loadSharedAssets()
dispatch_async(dispatch_get_main_queue(), {
handler()
})
})
}
@veeneck
veeneck / static.swift
Created June 17, 2014 19:11
Swift Static Var
class Flag : SKSpriteNode {
struct FlagSingleton {
static var texture = SKTexture[]()
static var onceToken: dispatch_once_t = 0
}
class func loadSharedAssets() {
dispatch_once(&FlagSingleton.onceToken, {
FlagSingleton.textures.append(SKTexture(imageNamed:"flag_castle"))
@veeneck
veeneck / callback.swift
Created June 17, 2014 19:17
Callback Definition
class func loadSceneAssetsWithCompletionHandler(handler:()->()) {
}