Question

I'm starting to develop a game, and in a moment I need to show a circle which increases its size, I got that, but the problem is that it increases its size and change its position and finally disappear from the screen. I want it to stay on its initial position and increase its size from the initial center.

My code is the following:

CGRect circle = CGRectMake(skRand(0, self.size.width), skRand(0, self.size.height), 20, 20);
SKShapeNode *shapeNode = [[SKShapeNode alloc] init];
shapeNode.position = CGPointMake(skRand(0, self.size.width), skRand(0, self.size.height));
shapeNode.path = [UIBezierPath bezierPathWithOvalInRect:circle].CGPath;
shapeNode.fillColor = [SKColor blueColor];
shapeNode.strokeColor = nil;
[self addChild:shapeNode];
SKAction* zoom = [SKAction scaleTo:15.0 duration:10.0];
[shapeNode runAction:zoom];

Any ideas?

Than you very much!

Was it helpful?

Solution

If you want your circle to increase size from the center, try constructing the circle not by using CGRectMakebut instead use a CGMutablePathRef, make the path and set the circle's path to the one you created. I have something similar in my game and this worked for me:

SKShapeNode *turnSphere = [[SKShapeNode alloc] init];
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddArc(path, NULL, 0, 0, 30, 0.0, (2 * M_PI), NO);
    turnSphere.path = path;
    turnSphere.position = CGPointMake(220, 440);
[self addChild:turnSphere];

    [turnSphere runAction:[SKAction scaleBy:3 duration:2]];

The circle should now scale up from the center. Hope this works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top