Sprite Kit SKShapeNode创建两个节点而不是一个节点

时间:2013-10-18 17:50:08

标签: ios sprite-kit

我是iOS的Sprite Kit新手。我想在场景中添加一个形状节点。场景是灰色的,形状是场景中心的白色圆圈。我的场景代码如下。由于某种原因,将节点添加到场景的最后一行导致节点计数增加2。如果我离开那条线,那么就有0个节点,只有灰色场景。但是如果我离开该行,那么圆圈就在那里,但是节点数是2.这是一个很大的问题,因为当我向圆圈添加更多节点时,节点数量应该是它应该是的两倍并且减慢了速度。谁知道问题是什么?非常感谢!

@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

1 个答案:

答案 0 :(得分:15)

您可以获得+1节点,用于将填充添加到圈子

所以,

- (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];

}