加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 04:51:39 所属栏目:百科 来源:网络整理
导读: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:
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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读