I'm new to iOS's Sprite Kit. I want to add a shape node to my scene. The scene is gray, and the shape is a white circle in the center of the scene. My scene code is below. For some reason the last line that adds the node to the scene causes the node count to go up by two. If I leave that line out, there's 0 nodes and just a gray scene. But if I leave the line then the circle is there but the node count is 2. This is a big problem because as I add more nodes to the circle the node count is double what it should be and slows things down. Anyone know what the problem is? Much appreciated!
@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
You get +1 node for adding the 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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With