Why has the coordinate system in the sprite set turned upside down and can I change it around the world?

I noticed that in the Sprite Kit the coordinate system is upside down.

For example, here is SKSpriteNode:

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

The car is positioned in the center of its parent.

When I set the position:

 car.position = CGPointMake(-50, 0); 

then it is positioned more to the left. But when I want to move it and increase Y, it moves up!

 car.position = CGPointMake(-50, 20); 

In UIKit, increasing Y always means that something is moving down. It seems more logical to me. Is there a way to flip the coordinate system in the Sprite Kit?

+7
sprite-kit skspritenode
source share
2 answers

The yScale scene yScale can be set to -1. Everything will turn upside down, but you can also set the yScale property for each node to -1, which will cause them to be displayed on the right side up.

You can also create a class and create the invertedPosition property using the custom getter / setter method, which inverts the default position property.

+7
source share

Sprite Kit uses a coordinate orientation starting at the bottom left corner of the scene (0,0), and the values ​​increase as you move right (increase x) and up (increase y).

+2
source share

All Articles