Skip to content

Instantly share code, notes, and snippets.

@sarah-j-smith
Created October 30, 2015 01:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarah-j-smith/bd10d7448233473c2951 to your computer and use it in GitHub Desktop.
Save sarah-j-smith/bd10d7448233473c2951 to your computer and use it in GitHub Desktop.
Create a disabled appearance for a button or other SKNode
import Foundation
import SpriteKit
class Button : SKEffectNode
{
var buttonEnabled: Bool = true {
didSet {
if oldValue != buttonEnabled
{
updateEnabled()
}
}
}
private func updateEnabled()
{
if buttonEnabled {
filter = nil
}
else
{
let desaturateFilter = CIFilter(name: "CIColorControls")!
desaturateFilter.setValue(0.0, forKey: kCIInputSaturationKey)
filter = desaturateFilter
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment