Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to SKShapeNode

I have a game designed with SpriteKit which heavily relies on 1 SKShapeNode (Which is a line). I'm making the line like this:

        if let path = createPathToMove() {
        let shapeNode = SKShapeNode()
        shapeNode.path = path
        shapeNode.name = "line"
        shapeNode.strokeColor = UIColor.blackColor()
        shapeNode.lineWidth = 20
        shapeNode.zPosition = 5
        shapeNode.antialiased = false
        shapeNode.lineCap = kCGLineCapRound
        self.world!.addChild(shapeNode)
    }

Unfortunately, since this was designed as a debug feature (Sprite-kit drawing), it is not optimized for what I'm doing, and a bigger problem is the line has artifacts (Since it's line width is greater than 2). Those look like this: http://i.stack.imgur.com/ccQ1s.png

With this in mind, I've deducted that using Sprite-kit's SKShapeNode isn't an option for me, unless someone knows how to fix the mentioned problems. I've looked into cocos2d, however it seems like that is a bit overkill (Using the entire lib for just a CCDrawNode). Is there any open source/public extensions for SKShapeNode (and swift), that improves the drawing feature? The most important thing to be fixed is the artifacts (white dots/lines in the node). If there isn't anything public, is Cocos2d my best choice?

like image 394
Aaron Avatar asked Jun 25 '15 20:06

Aaron


1 Answers

Although this post is a bit old, I thought I might as well answer it myself incase anyone else has the same problem.

Basically, to remove the artifacts in the line, you want to set the line width to a size smaller than 2.0 (For whatever reason no artifacts occur when it is smaller than this). After setting the line width, you will want to scale up the SKNode like so:

node.xScale = 10
node.yScale = 10

This will then make the line appear significantly thicker than it is, and there is no artifacts in the line.

You may also have to set the antialiased property to false, otherwise the line will appear very fuzzy.

like image 70
Aaron Avatar answered Oct 24 '22 22:10

Aaron