2

I'm training my SpritKit skills, but I can't figure out why my SKShapeNode are "reversed", I think I'm missing something.

I was trying example from this question: Question

So, I tried the example with 2 rounded corners, and another example which is a half-circle.

I don't understand why the two corners curved are not the one specified on the UIBezierPath object.

class GameScene: SKScene {

override func didMove(to view: SKView) {
    let rectangle = CGRect(x: 0, y: 0, width: 400, height: 400)
    let path = UIBezierPath(roundedRect: rectangle, byRoundingCorners: [.topLeft, .bottomRight], cornerRadii: CGSize(width: 50, height: 50))

    let shape = SKShapeNode(path: path.cgPath, centered: true)
    shape.lineWidth = 3

    addChild(shape)
}

}

enter image description here

And why, my half circle are not oriented in the good direction either.

While in the documentation - Apple documentation - It says:

For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the clockwise parameter to true draws the bottom half of the circle.

class GameScene: SKScene {

override func didMove(to view: SKView) {
    let path = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 200, startAngle: 0, endAngle: CGFloat(M_PI), clockwise: true)
    let shape = SKShapeNode(path: path.cgPath, centered: true)
    shape.lineWidth = 3

    addChild(shape)
}

}

enter image description here

Finally, can some one explain me how the array of 'corners' is considered as a mask?

Community
  • 1
  • 1
Scotow
  • 432
  • 7
  • 8
  • 2
    Likely because CGPath and UIBezierPath use different coordinate systems. For UIKit that is upper-left-origin coordinate system and for CoreGraphics that is lower-left-coordinate system. – Whirlwind Feb 06 '17 at 08:22
  • 3
    Whirlwind is correct. See [this](http://stackoverflow.com/questions/36807199/why-cgpath-and-uibezierpath-define-clockwise-differently-in-spritekit). You can flip the bezier path with an affine transform or create the shape with a `CGPath`. – 0x141E Feb 06 '17 at 10:07

0 Answers0