blitzeus
blitzeus

Reputation: 495

iOS circles and lines in Sprite Kit

I want to draw a circle and a line from from the circles center which is also twice as long as the circle's radius

My output is drawing a circle with the line next to it.

- (void)setupMainBall {
    mainBall = [self makeMainBall];
    mainBall.position = CGPointMake(self.size.width / 2, self.size.height / 2);
    mainBall.zPosition = 3;

    [self addChild:mainBall];
    [mainBall addChild:[self makeCanon]];
}

-(SKShapeNode *)makeMainBall {
    SKShapeNode *theMainBall = [[SKShapeNode alloc] init];
    CGMutablePathRef myPath = CGPathCreateMutable();
    CGPathAddArc(myPath, NULL, 0, 0, 10, 0, M_PI*2, YES);

    theMainBall.fillColor = [SKColor blueColor];
    theMainBall.path = myPath;
    theMainBall.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:theMainBall.frame.size.width / 2];

    return theMainBall;
}

-(SKSpriteNode *)makeCanon {
    canon = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(3, 20)];
    canon.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:canon.frame.size];
    return canon;
}

Upvotes: 0

Views: 628

Answers (1)

mad pig
mad pig

Reputation: 788

Try:

SKSpriteNode *canon = [self makeCannon];
[mainBall addChild:canon];
canon.position = CGPointMake(mainBall.size.width / 2, mainBall.size.width /2);

Upvotes: 1

Related Questions