How to set a lineWidth less than 1 for SKShapeNode?
Asked Answered
D

2

11

I'm trying to make an SKShapeNode with a very think stroke (like 0.25 pixel). It seems that lineWidth of 1 is the smallest I can go, at least that's what it looks like on screen no mater what value less than 1 is set.

SKShapeNode *buttonOutline;
buttonOutline = [[SKShapeNode alloc] init];

CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddRoundedRect(myPath, NULL, CGRectMake(0, 0, 100, 30), 10, 10);    
buttonOutline.path = myPath;
buttonOutline.strokeColor=[SKColor grayColor];

buttonOutline.lineWidth= 0.25;

buttonOutline.name = [NSString stringWithFormat:@"%@-buttonOutline", thisButtonName];
buttonOutline.position =  CGPointMake(thisXPos,thisYPod);
buttonOutline.alpha = 1;
Decontrol answered 18/12, 2013 at 14:36 Comment(0)
C
13

Try setting the antialiased property to false. The antialias adds some extra pixels around.

// Objective-C
buttonOutline.antialiased = NO

// Swift
buttonOutline.antialiased = false
Claritaclarity answered 28/1, 2014 at 15:5 Comment(1)
Thanks for that, this works, I couldn't find this anywhere in the docsCursed
B
1

Set scale to .25 and remember to properly upscale co-ordinates (multiply by 4 in this case)

Briareus answered 21/2, 2014 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.