Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...