Created
April 10, 2022 19:49
-
-
Save romyilano/e93cc2b0030f9bbe2d9172daaeeb2f02 to your computer and use it in GitHub Desktop.
Creating a skew in SpriteKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/43532815/1492368 | |
extension SKSpriteNode { | |
func addSkew(value: CGFloat = -1){ | |
var effectNode = SKEffectNode() | |
effectNode.shouldRasterize = true | |
effectNode.shouldEnableEffects = true | |
effectNode.addChild(SKSpriteNode(texture: texture)) | |
effectNode.zPosition = 1 | |
let transform = CGAffineTransform(a: 1 , b: 0, | |
c: value, d: 1, | |
tx: 0 , ty: 0) | |
let transformFilter = CIFilter(name: "CIAffineTransform")! | |
transformFilter.setValue(transform, forKey: "inputTransform") | |
effectNode.filter = transformFilter | |
addChild(effectNode) | |
texture = nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment