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?

openfrog
  • 40,201
  • 65
  • 225
  • 373

2 Answers2

10

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.

godel9
  • 7,340
  • 1
  • 33
  • 53
0

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).

Vingdoloras
  • 109
  • 8
alpennec
  • 1,864
  • 3
  • 18
  • 25