Oliver Redeyoff
Oliver Redeyoff

Reputation: 197

Coordinate system in swift ios is wrong

I am trying to position a sprite at a point :

class GameScene: SKScene {

    let player = SKSpriteNode(imageNamed: "Koopa_walk_1.png")

    override func didMove(to view: SKView) {
        player.position = CGPoint(x: 0, y: 0)
        self.addChild(player)
        print(koopa.get_x())
    }
}

But for some reason my sprite appears in more or less the middle of the screen :

enter image description here

Edit :

This is the original image (260px by 320px) :

enter image description here

I expected to see the image appear in the top left because it's coordinates are (0, 0)

Upvotes: 1

Views: 686

Answers (1)

Confused
Confused

Reputation: 6278

The coordinate system of SpriteKit is cartesian, with an origin default of the middle of the screen, when using the starting template in Apple's Xcode.

This template sets the origin to the centre of the screen by using an origin setting of (0.5, 0.5)

To have a top left origin, you're going to need set this to (0, 1), and then invert Y values, to negative values.

Upvotes: 7

Related Questions