Is it possible to add a border to SKSpriteNode similar to UIView?

I am wondering if it is possible to make SKSpriteNode to simulate the behavior of a UIView , where can I specify the border and radius of the corner?

 self.view.layer.borderColor = [UIColor lightGrayColor].CGColor; self.view.layer.borderWidth = 2; self.view.layer.cornerRadius = 2; self.view.layer.masksToBounds = YES; 
+8
source share
2 answers

Not initially. Although you can just add SKShapeNode as a child, the path which you are creating with CGPathCreateWithRoundedRect .

+4
source

Below is a simple incremental extension for SKSpriteNode that allows you to draw a border of a given color around your node.

 import SpriteKit extension SKSpriteNode { func drawBorder(color: UIColor, width: CGFloat) { let shapeNode = SKShapeNode(rect: frame) shapeNode.fillColor = .clear shapeNode.strokeColor = color shapeNode.lineWidth = width addChild(shapeNode) } } 
+8
source

All Articles