7

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?

4

2 回答 2

10

您可以将场景的yScale属性设置为 -1。一切都会颠倒渲染,但您也可以将yScale每个节点的属性设置为 -1,这将导致它们正面朝上渲染。

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

于 2013-12-22T21:09:22.507 回答
1

Sprite Kit 使用从场景左下角 (0,0) 开始的坐标方向,并且随着向右(增加 x)和向上(增加 y)移动,值会增加。

于 2014-03-26T08:49:12.637 回答