I have a SpriteKit game which I want to support all orientations. Right now when I change the orientation, the node doesn\'t keep its position. I use the SKSceneScaleM
For Swift 3,
override func didChangeSize(_ oldSize: CGSize) {
for node in self.children{
let newPosition = CGPoint(x:node.position.x / oldSize.width * self.frame.size.width,y:node.position.y / oldSize.height * self.frame.size.height)
node.position = newPosition
}
}
Thus we are able to use a constant and initialise it in one line. Then in node.position = newPosition
we can set the new position.
Also we are able to make use of the enhanced for loop leading to a much more elegant solution.