LoginSignup
5
1

More than 3 years have passed since last update.

SpriteKitで円を描画する

Last updated at Posted at 2019-06-17

SpriteKitでの円の描画方法です。オプションにより角丸の四角形も描画可能です。
cornersの値によってどの角を丸くするか指定することもできます。
また、「shape.path = UIBezierPath(roundedRect: rec, byRoundingCorners: corners, cornerRadii: size).cgPath」の行の「size」を「CGSize(width: 25, height: 25)」などに書き換えることにより円だけではなく角丸の四角形を描画することもできました。

        //SKShapeNodeを宣言
        let shape = SKShapeNode()
        //位置とサイズを指定
        let rec = CGRect(x:0, y:0, width:100, height:100);
        //丸くする角を指定する
        let corners : UIRectCorner = [UIRectCorner.topLeft,UIRectCorner.topRight,UIRectCorner.bottomLeft,UIRectCorner.bottomRight]
        //角の丸さを指定
        shape.path = UIBezierPath(roundedRect: rec, byRoundingCorners: corners, cornerRadii: size).cgPath
        //色を指定
        shape.fillColor = UIColor.red
        shape.strokeColor = UIColor.white
        //シーンに追加
        self.addChild(shape)


Simulator Screen Shot - iPhone Xʀ - 2019-06-17 at 22.25.54.png

角丸四角
Simulator Screen Shot - iPhone Xʀ - 2019-06-17 at 22.25.02.png

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1