Vertical Dashed Line using SpriteKit SKShapeNode


In my latest game, I need to show a dashed vertical line when user break his previous record.

SKShapeNode

The following code is used to create the red dashed line.

func getVerticalLineShapeNode() -> SKShapeNode {
let bezierPath = UIBezierPath()
let startPoint = CGPointMake(0, 0)
let endPoint = CGPointMake(0, 1536)
bezierPath.moveToPoint(startPoint)
bezierPath.addLineToPoint(endPoint)

let pattern : [CGFloat] = [50.0, 30.0]
let dashed = CGPathCreateCopyByDashingPath (bezierPath.CGPath, nil, 0, pattern, 2)

let shapeNode = SKShapeNode(path: dashed!)
shapeNode.name = "redLines"
shapeNode.strokeColor = SKColor.redColor()
shapeNode.xScale = 3.0
return shapeNode
}

Using startPoint and endPoint (X,Y) you can make the line vertical or horizontal.
Pattern is used to show the dash part and gap part between dashes.
And in the shapeNode you can select color and stroke size.

mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage