ios – 更改SKShapeNode的半径

ios – 更改SKShapeNode的半径,第1张

概述如何在不重新创建的情况下更改SKShapeNode的半径?在头文件中,只有一个带有circleOfRadius语法的初始化器. 如果使用路径创建SKShapeNode,则可以稍后更改路径.试试这个: class GameScene: SKScene { override func mouseDown(theEvent: NSEvent) { let location = t 如何在不重新创建的情况下更改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,radius,2.0 * M_PI,true)        return path    }}

这与缩放之间的区别在于,除非您制作它们,否则您设置的任何其他内容(例如行宽,文本子节点等)都不会更改.

总结

以上是内存溢出为你收集整理的ios – 更改SKShapeNode的半径全部内容,希望文章能够帮你解决ios – 更改SKShapeNode的半径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1073808.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存