Reputation: 3914
I am building a game and I would like to be able to rotate a node. I can rotate is perfectly fine if the parent of that node is self
(The GameScene), but if I add the node as a child of another node that doesn't have the same width x height
ratio, it looses it's aspect ratio.
I thought I could simply find the scene ratio and multiply the node's width by it after changing parent, and this works fine but... When I rotate the node (zRotation), it stretches again. The maximum stretch is when the node is rotated at 90 degrees, as the new parent node is a rectangle that is higher than larger.
I was wondering if there is a way to always keep the aspect ration intact even when rotating and change node parent (coordinate system)?
I simply add nodes to bigRectangle (a big rectangle on the GameScene). It looks stretched on the rectangle (it does not if I add it to the GameScene) so I change the ratio by doing:
let myRatio = self.frame.height / self.frame.width
myNode.xScale = 1
myNode.yScale = 1 * myRatio
This works but when the node is rotated (zRotation) it becomes stretched again...
I added pictures;
Upvotes: 2
Views: 392
Reputation: 5451
You have to configure this on the scene itself:
scene.scaleMode = .AspectFill
Upvotes: 0