IN Siwft 3, I could not find CGRectGetMidX and Y which I used to calclate position of nodes. Also I could not find CGPointMake. IN this case, how am I able to set nodes in the center of SKScene?
Thanks!
Update: I created a node and specified the position of it, by writing this way;
let node = SKSpriteNode()
node.position = CGPoint(x:self.frame.size.width/2, y:self.frame.size.height/2)
node.size = CGSize(width: 100, height: 100)
node.color = SKColor.red
self.addChild(node)
Why is it somewhere else like different place from the specified location? I firstly thought there was a change in Swift3 and the depresciation of CGPointMake caused this problem, but it does not seem like it is the cause. In this case, is the use of CGRect better? It is very helpful if you could write code that fixs this position issue. Again, thank you for your help.
In Swift you shouldn't use those old style notations. Just use the constructors and properties:
C global functions like
CGRectGetMidX
/Y
,CGPointMake
, etc. shouldn't be used in Swift (they're deprecated in Swift 2.2, removed in Swift 3).Swift imports
CGRect
andCGPoint
as native types, with initializers, instance methods, etc. They're much more natural to use, and they don't pollute the global name space as the C functions once did.Their respect API reference is linked above. You might also find the CoreGraphics API reference handy too.
Have too many center calculations in your code. Use this.