向 SKLabelNode 添加背景
Adding a background to a SKLabelNode
我一直在尝试在我的 SKLabelNode 周围添加背景,但我不知道如何在 swift 中以编程方式执行此操作 3. 我看到一些使用 .background 的旧帖子,但事实并非如此为我工作。
let background = SKSpriteNode(color: UIColor.white, size: CGSize(width: CGFloat((title.frame.size.width)), height:CGFloat((title.frame.size.height))))
background.zPosition = -1
background.position = CGPoint(x: self.frame.width / 12 * 6, y: self.frame.height / 12 * 11); title.addChild(background)
检查这个新代码,我认为它更适合你的问题
let shape = SKShapeNode()
shape.path = UIBezierPath(roundedRect: CGRect(x:(label?.frame.origin.x)! - 15, y: (label?.frame.origin.y)! - 15, width: ((label?.frame.size.width)!+30), height: ((label?.frame.size.height)! + 50 )), cornerRadius: 64).cgPath
shape.position = CGPoint(x: frame.midX, y: frame.midY)
shape.fillColor = UIColor.red
shape.strokeColor = UIColor.blue
shape.lineWidth = 5
label?.addChild(shape)
我一直在尝试在我的 SKLabelNode 周围添加背景,但我不知道如何在 swift 中以编程方式执行此操作 3. 我看到一些使用 .background 的旧帖子,但事实并非如此为我工作。
let background = SKSpriteNode(color: UIColor.white, size: CGSize(width: CGFloat((title.frame.size.width)), height:CGFloat((title.frame.size.height))))
background.zPosition = -1
background.position = CGPoint(x: self.frame.width / 12 * 6, y: self.frame.height / 12 * 11); title.addChild(background)
检查这个新代码,我认为它更适合你的问题
let shape = SKShapeNode()
shape.path = UIBezierPath(roundedRect: CGRect(x:(label?.frame.origin.x)! - 15, y: (label?.frame.origin.y)! - 15, width: ((label?.frame.size.width)!+30), height: ((label?.frame.size.height)! + 50 )), cornerRadius: 64).cgPath
shape.position = CGPoint(x: frame.midX, y: frame.midY)
shape.fillColor = UIColor.red
shape.strokeColor = UIColor.blue
shape.lineWidth = 5
label?.addChild(shape)