3 Replies
      Latest reply on Jul 5, 2016 2:03 AM by pavelgubarev
      Carniphage Level 1 Level 1 (15 points)

        I am using a SpriteKit layer as a HUD.  The layer include  2d sprite elements, and I need a couple of procedural line-draws.

        This means each tick replacing the SKShapeNode's path with a new one.   Which I am building with CGMutablePath

         

        This works for about 10 seconds, and then there's a crash. (EXC_BAD_ACCESS)  Usually the debugger shows Main/ApplicationDelegate

        But digging around in the stack reveals it is something going on in the line draw.

         

        
        let relTrail:[CGPoint] = [CGPoint(0,0),CGPoint(0,-10),CGPoint(-10,-20)]         /
        let startPt = relTrail[0]
        let path = CGPathCreateMutable()
        CGPathMoveToPoint(path, nil, startPt.x, startPt.y)
        for pt in relTrail
        {
            CGPathAddLineToPoint(path , nil , pt.x , pt.y)
        }
        self.shapeNode.path = path
        
        

         

        Looking at the documention it feels like SKShapeNode supports path drawing, but does not expect the path to be dynamically changed once per frame.

         

        Are there, perhaps some other ways to accomplish the same goal?