2013-10-18 12 views
8

Sono nuovo al kit Sprite di iOS. Voglio aggiungere un nodo di forma alla mia scena. La scena è grigia e la forma è un cerchio bianco al centro della scena. Il mio codice di scena è sotto. Per qualche motivo l'ultima riga che aggiunge il nodo alla scena fa salire il conteggio dei nodi di due. Se lascio questa linea, ci sono 0 nodi e solo una scena grigia. Ma se lascio la linea, allora il cerchio è lì ma il numero dei nodi è 2. Questo è un grosso problema perché quando aggiungo più nodi al cerchio il numero dei nodi è doppio di quello che dovrebbe essere e rallenta le cose. Qualcuno sa qual è il problema? Molto apprezzato!Sprite Kit SKShapeNode che crea due nodi invece di uno

@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 
+0

hai verificato che creano contenuti scena è veramente mai essere chiamato una volta? magari inserire un login o punto di rottura – AwDogsGo2Heaven

+0

Sì. Ho messo un registro lì ed è chiamato solo una volta. – Hash88

+0

Quindi, se ho capito bene, se si aggiunge questa forma una volta, si dice che sono "due" nodi, se la si aggiunge due volte si direbbe che sono "quattro" nodi. – AwDogsGo2Heaven

risposta

15

Si ottiene 1 nodo per aggiungere il riempimento al cerchio

Quindi,

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

} 
+0

Ah questo è il problema. Grazie mille Smick! – Hash88

+0

Pollice in alto :-) Sì, è ancora strano ma ... se sei soddisfatto della risposta, spunta corretto, quindi la domanda è stata risolta. – DogCoffee

Problemi correlati