问题
I noticed that in Sprite Kit the coordinate system is flipped.
For example, here is a SKSpriteNode:
SKSpriteNode *car = [SKSpriteNode spriteNodeWithImageNamed:@"car"];
car.position = CGPointMake(0, 0);
[road addChild:car];
The car is positioned in the center of it's parent.
When I set position to:
car.position = CGPointMake(-50, 0);
then it is positioned more to the left. But when I want to move it down, and increase Y, it moves UP!
car.position = CGPointMake(-50, 20);
In UIKit increasing Y always means something moves down. It feels more logical to me. Is there a way to flip the coordinate system in Sprite Kit?
回答1:
You can set your scene's yScale
property to -1. Everything will render upside down, but you can also set the yScale
property for each node to -1, which will cause them to render right side up.
You could also make a class category and create a property called invertedPosition
with a custom getter/setter that inverts the default position
property.
回答2:
Sprite Kit uses a coordinate orientation that starts from the bottom left corner of the scene (0,0), and the values increase as you move to the right (increasing x) and up (increasing y).
来源:https://stackoverflow.com/questions/20733953/why-is-the-coordinate-system-in-sprite-kit-flipped-and-can-i-change-that-globall