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 [Business | Twitter | Linkedin | Instagram | Flickr | 500px]

You may also like

LEAVE A COMMENT

About Me

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

Flickr

Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed
Flickr Feed

Twitter Feed

Fanpage