0

I have a SKLabelNode that I want positioned centre, however I have had to align the label node left and bottom to remove the well documented "jitter effect". I currently set up the scene by positioning nodes by allocating their position using the following function:

  func gridPointX(xPoint:CGFloat, pointY:CGFloat) -> CGPoint  {

    var xDivision:CGFloat = CGRectGetMaxX(frame)/5.0
    var yDivision:CGFloat = CGRectGetMaxY(frame)/5.0
    return CGPointMake(xPoint*xDivision, pointY*yDivision)



}

This works fine until I remove the "jitter effect" by using the following code:

   myDateLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left
   myDateLabel.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Bottom

I have tried to manually enter the x and y positions into the code via the following:

myDateLabel.position = self.gridPointX(0, pointY: 3.6)

However, this produces different label positions dependant on the device type. If I could work out the length of the SKLabelNode I could no doubt determine the centre, I've searched the documentation but can't get a solution. Any thoughts guys?

Tom
  • 790
  • 2
  • 9
  • 32
  • You cannot get the actual length of a label node. You will have to base your position by using calculations based on the device screen dimensions to make it more generic. – sangony Apr 30 '15 at 23:56
  • I suspected so, sangony, I just wondered if an easier solution was possible. – Tom May 01 '15 at 07:04
  • You CAN get the width of an SKLabel node after you set the text property. Use the `calculateAccumulatedFrame.width` to get the current width of the label node. – hotdogsoup.nl Jun 01 '19 at 12:35

0 Answers0