gpt4 book ai didi

ios - 改变 SKShapeNode 的半径

转载 作者:搜寻专家 更新时间:2023-10-30 23:00:37 25 4
gpt4 key购买 nike

我们如何在不重新创建 SKShapeNode 的情况下更改它的半径?在头文件中只有一个带有 circleOfRadius 语法的初始化程序。

最佳答案

如果您使用路径创建 SKShapeNode,您可以在以后随时更改路径。试试这个:

class GameScene: SKScene {
override func mouseDown(theEvent: NSEvent) {
let location = theEvent.locationInNode(self)
let node = self.nodeAtPoint(location)
if let circle = node as? SizeableCircle { // clicking on an existing circle
circle.radius = Double(arc4random_uniform(100))
} else { // clicking on empty space
self.addChild(SizeableCircle(radius: 100.0, position: location))
}
}
}

class SizeableCircle: SKShapeNode {

var radius: Double {
didSet {
self.path = SizeableCircle.path(self.radius)
}
}

init(radius: Double, position: CGPoint) {
self.radius = radius

super.init()

self.path = SizeableCircle.path(self.radius)
self.position = position
}

class func path(radius: Double) -> CGMutablePathRef {
var path: CGMutablePathRef = CGPathCreateMutable()
CGPathAddArc(path, nil, 0.0, 0.0, radius, 0.0, 2.0 * M_PI, true)
return path
}

}

这与缩放之间的区别在于,您设置的任何其他内容(例如线宽、文本子节点等)不会改变,除非您进行设置。

关于ios - 改变 SKShapeNode 的半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24330977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com