Created
July 22, 2015 22:19
-
-
Save brocoo/30fba1b054aaf8cc5dea to your computer and use it in GitHub Desktop.
CGPoint extension for 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
extension CGPoint { | |
public enum CoordinateSystem { | |
case UIKit | |
case SpriteKit | |
} | |
public func coordinates(from from: CoordinateSystem, to: CoordinateSystem) -> CGPoint { | |
if from == to { return self } | |
else { | |
return CGPoint(x: self.x, y: -self.y) | |
} | |
} | |
} | |
public func +(lhs: CGPoint, rhs: CGPoint) -> CGPoint { | |
return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y) | |
} | |
public func -(lhs: CGPoint, rhs: CGPoint) -> CGPoint { | |
return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y) | |
} | |
public func +=(inout lhs: CGPoint, rhs: CGPoint) { | |
lhs = lhs + rhs | |
} | |
public func -=(inout lhs: CGPoint, rhs: CGPoint) { | |
lhs = lhs - rhs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment