微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – 使用SKShapeNode在Sprite Kit中绘制虚线

I fount this solution but I can’t make it into swift code

这就是我的尝试

var pattern[2]:CGFloat; this 

var dashed: CGPathRef = CGPathCreatecopyByDashingPath(CGPathCreatecopyByDashingPath(path,transform,phase,lengths,count);

var myShapeNode: SKShapeNode!;

        var CGPathCreatecopyByDashingPath:CGPathRef;

解决方法

这是你在swift中绘制虚线的方法.您可以根据需要更改参数.

let bezierPath = UIBezierPath()
let startPoint = CGPointMake(0,250)
let endPoint = CGPointMake(450,250)
bezierPath.movetoPoint(startPoint)
bezierPath.addLinetoPoint(endPoint)

var pattern : [CGFloat] = [10.0,10.0]
let dashed = CGPathCreatecopyByDashingPath (bezierPath.CGPath,nil,pattern,2)

var shapeNode = SKShapeNode(path: dashed)
shapeNode.position = CGPointMake(100,100)
self.addChild(shapeNode)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐