I have my own class inheriting from SKNode and would like to implement SKSpriteNode functionality with an anchor in this class. In particular, I am trying to achieve a centralized user node in the parent node automatically (anchorPoint by 0.5, 0.5) without having to offset it by half its width / height.
Any tips?
Change . I ended up creating an anchorPoint variable first and then overriding the position variable and setting the superposition changed by the anchor.
var anchorPoint = CGPoint(x: 0.5, y: 0.5)
override var position: CGPoint {
set {
super.position = CGPoint(x: self.position.x - self.size.width * self.anchorPoint.x, y: self.position.y - self.size.height * self.anchorPoint.y)
}
get {
return super.position
}
}
source
share