2017-08-31 6 views
0

丸い四角形のUIBezierPathがあります。ここでは形状のために私のコードですenter image description hereUIBezierPathのセンタリング

let shape = SKShapeNode() 
    shape.path = UIBezierPath(roundedRect: CGRect(x:(0), y: (0), width: (250), height: (400)), cornerRadius: 64).cgPath 
    shape.position = CGPoint(x: 0, y: 0) 
    print(shape.position) 
    shape.fillColor = UIColor.white 
    shape.strokeColor = UIColor.white 
    shape.lineWidth = 5 
    addChild(shape) 

私は画面の中央に、それを中央にしたいのですが、

shape.position = CGPoint(x: self.frame.width, y: self.frame.height) 

を使用して動作しません。それは多少このようになります。ありがとう!

答えて

0

UIBezierPathをシェイプノードの中央に配置することをお勧めします。たとえば、

let width:CGFloat = 250 
let height:CGFloat = 400 
shape.path = UIBezierPath(roundedRect: CGRect(x:-width/2, y: -height/2, width: width, height: height), cornerRadius: 64).cgPath 

位置を(0、0)に設定することで、シーンの中心を合わせることができます。