我已经在网上搜索并在堆栈溢出中找到了这个答案 here
答案并没有完全满足我的要求,可能是因为它是用objective c写的。
我在网上搜索了如何圈一个 SKSpriteNode 并没有找到答案,尽管如此 这是我试过的一些代码:
let cropNode = SKCropNode()
let mask = SKShapeNode()
mask.path(CGPathCreateWithRoundedRect(CGRectMake(-15, -15, 30, 30), 4, 4, nil));
// ↳ '(CGPath!)-> $T13' is not identical to 'CGPath'
cropNode.maskNode(mask)
// ↳ cannot convert the expression's type 'SKShapeNode'to type 'SKNode?'
cropNode.addChild(plate)
错误如上面的注释所示。
我想让我的 SKSpriteNode 变成圆角或者换句话说,让它变成一个圆。 这是我声明的 SKSpritenode:
var foodarea = SKSpriteNode(imageNamed: "plate")
这是我要圈出的图像,显示为 here
谢谢!
请您参考如下方法:
您似乎混淆了函数调用语法和赋值语法。
let cropNode = SKCropNode()
let mask = SKShapeNode()
mask.path = CGPathCreateWithRoundedRect(CGRectMake(-15, -15, 30, 30), 4, 4, nil)
cropNode.maskNode = mask
