SKShapeNode(路径:路径)不绘制

时间:2016-06-23 23:17:42

标签: ios swift core-graphics skshapenode

这里我试图为我已成功创建SKShapeNode边框的网格绘制gridLines但是在运行此代码时我无法看到这些线条。

func drawGridLines() {
        print("drawing")
        for row  in 0...40 {
            let path = CGPathCreateMutable()
            CGPathMoveToPoint(path, nil, grid.frame.origin
                .x , grid.frame.origin.y + CGFloat(row * 10))
            CGPathAddLineToPoint(path, nil, grid.frame.width, grid.frame.origin.y + CGFloat(row * 10))
            let shape = SKShapeNode(path: path)
            shape.path = path
            shape.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame))
            shape.fillColor = UIColor.redColor()
            shape.strokeColor = UIColor.blueColor()
            shape.lineWidth = 10
            addChild(shape)

            for col in 0...90 {
                print("y")
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我将你的代码复制到我的项目并运行,我清楚地看到那些蓝色网格线。但是,我没有变量grid所以我将其更改为self SKScene。所以我认为你对grid有一些问题,也许它不在屏幕之外。添加更多关于它的代码或自行更改,进行一些测试。

enter image description here