Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position a node at the center of the screen in spritekit?

Tags:

ios

sprite-kit

In spritekit, is there a quick way to position a node at the center of the screen without having to calculate the coordinate manually?

like image 238
user1615898 Avatar asked Oct 26 '25 08:10

user1615898


1 Answers

if your scene has an anchorPoint of CGPoint(x: 0.5, y: 0.5) then any object you add to the scene will automatically be placed in the center of the screen.

If your scene has an anchorPoint of CPoint.zero (lower left corner) you can set the position of the object by setting object.position = CGPoint(x: self.size.width / 2, y: self.size.height/ 2) where self is the scene

like image 102
Ron Myschuk Avatar answered Oct 29 '25 08:10

Ron Myschuk