8

iOS のスプライト キットは初めてです。シーンにシェイプ ノードを追加したいと考えています。シーンは灰色で、形状はシーンの中央にある白い円です。私のシーンコードは以下です。何らかの理由で、ノードをシーンに追加する最後の行により、ノード数が 2 つ増えます。その行を除外すると、ノードが 0 になり、灰色のシーンだけになります。しかし、線を離れると、円はそこにありますが、ノード数は 2 です。これは大きな問題です。円にノードを追加すると、ノード数が本来の 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
4

1 に答える 1

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

}
于 2013-10-18T23:44:56.980 に答える