Skip to content

Instantly share code, notes, and snippets.

@veeneck
veeneck / shader2.fsh
Last active August 29, 2015 14:22
Detecting alpha values in a shader
void main() {
// Find the pixel at the coordinate of the actual texture
vec4 val = texture2D(u_texture, v_tex_coord);
// If the alpha value of that pixel is 0.0
if (val.a == 0.0) {
// Turn the pixel green
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
@veeneck
veeneck / shader1.swift
Created May 28, 2015 15:48
Attach a shader in SpriteKit
let sprite = self.childNodeWithName("targetSprite") as! SKSpriteNode
let shader = SKShader(fileNamed: "shader1.fsh")
sprite.shader = shader
@veeneck
veeneck / shader1.fsh
Created May 28, 2015 15:45
A basic shader
void main() {
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
}
@veeneck
veeneck / save.swift
Created April 2, 2015 16:37
Current save game data
import SpriteKit
class GameData : NSObject, NSCoding {
/// Each scene always knows what scene should come next.
/// So, by storing the current scene, we can just resume that scene when the game is reloaded
/// If the user quits on a level, use logic to show world map instead
/// NOTE** -- save SceneObject instead? so that userData is remembered, and it just pass this to scene manager?
var currentScene : String = "MainMenu"
@veeneck
veeneck / citransition.swift
Created February 9, 2015 16:39
example transition with CI Filter
// 5 - starburst out
let filter = CIFilter(name: "CIFlashTransition", withInputParameters: ["inputCenter":CIVector(x: 600, y: 900)])
let transition = SKTransition(CIFilter: filter, duration: 2)
@veeneck
veeneck / gamedata.swift
Last active November 4, 2016 15:46
Save game in SpriteKit
class GameData : NSObject, NSCoding {
/// Data to save
var variableA : Int = 1
var variableB : Int = 2
var variableC : Int = 3
@veeneck
veeneck / classtime.swift
Created January 26, 2015 14:35
Class timing
class CutsceneAction {
var finishEarly : Bool = false
func timingFunc(time:Float) -> Float {
if(self.finishEarly) {
return 1.0
}
else {
return time
@veeneck
veeneck / hardcoded.swift
Created January 26, 2015 14:25
SKAction Timing Funciton
func timingFunc(time:Float) -> Float {
return 1.0
}
let moveAction = SKAction.moveToX(500, duration: 0.2)
moveAction.timingFunction = timingFunc
@veeneck
veeneck / uilabeloutline.swift
Last active January 9, 2018 05:35
outline text uilabel
if let font = UIFont(name: "DamascusSemiBold", size: 24) {
let textFontAttributes = [
NSFontAttributeName : font,
// Note: SKColor.whiteColor().CGColor breaks this
NSForegroundColorAttributeName: UIColor.whiteColor(),
NSStrokeColorAttributeName: UIColor.blackColor(),
// Note: Use negative value here if you want foreground color to show
NSStrokeWidthAttributeName: -3
]
@veeneck
veeneck / updateService.swift
Created January 5, 2015 18:04
Update Loop Service
import SpriteKit
class UpdateService {
/// Handle on current SKScene
let scene : Level
/// Array of callbacks to be called each time the updateLoopRuns
var updateListeners : Array<((CFTimeInterval) -> ())> = []