Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems understanding coordinate system SpriteKit using Swift

I am having trouble fully grasping the coordinate system with SpriteKit using Swift. I have looked at many resources including apples dev docs but for some reason I am very confused (i'm sure this must be simple).

I have a GameScene class inheriting from SKScene. I am just trying to add a SKSpriteNode to the screen using various coordinates to get used to the screen layout. I believe that when you create any SKNode and give it a position by doing the following

var node = SKSpriteNode(color: UIColor.brownColor(), size: CGSizeMake(100, 100))
node.position = CGPointMake(0, 0)

and then place any SKNode using

self.addChild(node)

The coordinates that have been supplied to the node are coordinates in the parent node. Does this mean that the brown square that has been created should be placed at the bottom left corner?

This is obviously not the case and is what is confusing me. I am using the iPhone 5s simulator for testing in portrait.

The sprite node only appears in the bottom left when I set the position to (350, 50).

like image 563
kev3kev3 Avatar asked Jun 11 '14 12:06

kev3kev3


1 Answers

Select the GameScene.sks in the Project Navigator, select the SKScene (it should have a yellow border round it) and set its size property to 320 points x 569 points (this is assuming iPhone5 / 5S) either way this is the problem. Also make sure you double check it as I am sure it changed back to 1024x768 on me, but seems to be working now.

like image 54
fuzzygoat Avatar answered Oct 17 '22 00:10

fuzzygoat