Sprite Kit SKShapeNode creates two nodes instead of one

I am new to iOS Sprite Kit. I want to add a node shape to my scene. The scene is gray and the shape is a white circle in the center of the scene. The code for my scene is below. For some reason, the last line adding node to the scene, the node count is increased by two. If I leave this line, then there are 0 nodes and only a gray scene. But if I leave the line, then there is a circle, but the number of node is 2. This is a big problem, because when I add more nodes to the circle, the number of node doubles what it should be and slows down. Does anyone know what the problem is? Really appreciate!

@interface ColorWheelScene() @property BOOL contentCreated; @end @implementation ColorWheelScene - (void)didMoveToView:(SKView *)view { if(!self.contentCreated) { [self createSceneContents]; self.contentCreated = YES; } } - (void)createSceneContents { self.backgroundColor = [SKColor grayColor]; self.scaleMode = SKSceneScaleModeAspectFit; SKShapeNode *wheel = [[SKShapeNode alloc]init]; UIBezierPath *path = [[UIBezierPath alloc] init]; [path moveToPoint:CGPointMake(0.0, 0.0)]; [path addArcWithCenter:CGPointMake(0.0, 0.0) radius:50.0 startAngle:0.0 endAngle:(M_PI*2.0) clockwise:YES]; wheel.path = path.CGPath; wheel.fillColor = [SKColor whiteColor]; wheel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); [self addChild:wheel]; } @end 
+8
ios sprite-kit
source share
1 answer

You get a +1 node to add a fill to the circle

So,

 - (void) makeACircle { SKShapeNode *ball; ball = [[SKShapeNode alloc] init]; // stroke only = 1 node // CGMutablePathRef myPath = CGPathCreateMutable(); // CGPathAddArc(myPath, NULL, 0,0, 60, 0, M_PI*2, YES); // ball.path = myPath; // ball.position = CGPointMake(200, 200); // [self addChild:ball]; // stroke and fill = 2 nodes CGMutablePathRef myPath = CGPathCreateMutable(); CGPathAddArc(myPath, NULL, 0,0, 60, 0, M_PI*2, YES); ball.path = myPath; ball.fillColor = [SKColor blueColor]; ball.position = CGPointMake(200, 200); [self addChild:ball]; } 
+15
source share

All Articles