3

This issue has been happening for days: I cannot set the specific frame I need. I need my SKShapeNode frame to be the bounding box around a circle so that it is an inscribed circle to the frame.

enter image description here

The blue is the current frame and the red is the frame I want it to be. I am creating the SKShapeNode like this:

init(level: Int, from: SKSpriteNode, fromScene: GameScene) {
    self.level = level
    self.from = from
    self.fromScene = fromScene

    bezierPath = UIBezierPath(arcCenter: CGPoint.zero, radius: CGFloat(((25 * level)) + 50), startAngle: CGFloat(GLKMathDegreesToRadians(-50)), endAngle: CGFloat(M_PI * 2), clockwise: false)

    let top = CGFloat((level * 25) + 50)
    let bottom = CGFloat((level + 1) * 25 + 50)
    scale = top / bottom
    finalLineWidth = (initialLineWidth / scale)

    super.init()

    self.path = bezierPath.cgPath
    self.strokeColor = UIColor(red:0.98, green:0.99, blue:0.99, alpha:1.00)
    self.lineWidth = initialLineWidth

}

The frame is total wrong though. It is some random frame, you would think it would be set to calculateAcumulatedFrame. Where does it even get this wrong frame from...

So I overrode calculateAcumulatedFrame since frame is a get-only property:

override func calculateAccumulatedFrame() -> CGRect {
    let length = bezierPath.bounds.size.width + initialLineWidth
    let origin = CGPoint(x: bezierPath.bounds.origin.x - 5, y: bezierPath.bounds.origin.y - 5)
    return CGRect(origin: origin, size: CGSize(width: length, height: length))
}

And that returns the CGRect shown by the red part in the picture.

How do I get the calculateAccumulatedFrame to be applied to the frame? Nothing I do has it update the frame to calculateAccumulatedFrame. If it is not right, how else can I set the frame then?

xScale and yScale does not work at all. And by using it, the line width of the SKShapeNode is shrinked or enlarged and completely wrong. I need calculateAccumulatedFrame to work so I can specify the frame.

Any ideas?

ngngngn
  • 579
  • 4
  • 18
  • For someone to help, you're going to need to absolutely isolate the problem. Get rid of ALL OTHER CIRCLES, and just show one circle, and its problems with regards its frame, and whatever scaling you're doing. – Confused Nov 14 '16 at 13:54
  • Let me explain why: I take one look at this, and my eyes glaze over. I see someone having a problem that's mystifying, inherent and complex to solve, yet it's not certain they can explain and isolate that problem. Make it SUPER easy to see the problem, and not see ANYTHING else. – Confused Nov 14 '16 at 13:55
  • you reference blue, red, frame, this, that.... blah blah blah. The image has shades of purple, pink and an orange ball. Where do I start? – Confused Nov 14 '16 at 13:56

0 Answers0