Skip to content

Instantly share code, notes, and snippets.

@brocoo
Created July 22, 2015 22:19
Show Gist options
  • Save brocoo/30fba1b054aaf8cc5dea to your computer and use it in GitHub Desktop.
Save brocoo/30fba1b054aaf8cc5dea to your computer and use it in GitHub Desktop.
CGPoint extension for SpriteKit
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