How to set the position of SkSpriteNode relative to the visible area, so what will it be, for example, 50x50 from the corner on each device?
The "visible area" is just a view.
So, you can make your position regarding the view , not the scene . I really do a lot in my game, which is universal and works both on OS X and iOS.
In my case, I usually do this for the user interface, so I can have a scaled scene, but I want to set some positions not relative to the scaled scene, but relative to the visible area (i.e. the view).
To do this, you can write a function that converts the coordinates of the view into the corresponding coordinates of the scene.
Here is my function that I use. Note that I subtract the desired y position from the height of the view so that I can process (0,0) as the bottom left, as a sprite set, instead of the top left, as UIKit does.
func convert(point: CGPoint)->CGPoint { return self.view!.convertPoint(CGPoint(x: point.x, y:self.view!.frame.height-point.y), toScene:self) }
Here is an example of using this function:
self.node.position = convert(CGPoint(x: 50, y: 50))
This will always force the node position to be (50.50) relative to the view (visible portion of the screen) no matter how your scene is scaled and sized.
Epic Byte Mar 20 '15 at 16:18 2015-03-20 16:18
source share