为什么精灵工具包中的坐标系翻转,我可以全局更改吗?

ope*_*rog 7 sprite-kit skspritenode

我注意到在Sprite Kit中,坐标系被翻转.

例如,这是一个SKSpriteNode:

SKSpriteNode *car = [SKSpriteNode spriteNodeWithImageNamed:@"car"];
car.position = CGPointMake(0, 0);
[road addChild:car];
Run Code Online (Sandbox Code Playgroud)

汽车位于它的父母的中心.

当我设定位置时:

car.position = CGPointMake(-50, 0);
Run Code Online (Sandbox Code Playgroud)

然后它位于左侧.但是当我想把它向下移动并增加Y时,它会向上移动!

car.position = CGPointMake(-50, 20);
Run Code Online (Sandbox Code Playgroud)

在UIKit中,增加Y总是意味着向下移动.这对我来说更合乎逻辑.有没有办法在Sprite Kit中翻转坐标系?

god*_*el9 8

您可以将场景的yScale属性设置为-1.所有内容都会颠倒呈现,但您也可以将yScale每个节点的属性设置为-1,这将导致它们正面向上渲染.

您还可以创建一个类类别,并创建一个invertedPosition使用自定义getter/setter 调用的属性,该position属性可以反转默认属性.