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

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Github | Business | Twitter | Linkedin | Instagram | 500px]

You may also like

Comments are closed here.

About Me

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Github | Business | Twitter | Linkedin | Instagram | 500px]

500px

Muaz and Jayed First Smile Little Angel Trees Horse Ride Maritime Museum in Malacca Dome of Blue Mosque Malaysia Putrajaya Bridge in Sunny Day Blue Mosque in Malaysia

Twitter Feed

Fanpage