mprivat
mprivat

Reputation: 21912

scaling an SKSpriteNode on it's center

I have an SKSpriteNode. I want to make it get bigger and then smaller on its own. So I used a sequence of SKAction using [SKAction scaleTo:]. It works because the sprite has a bigger width and height, but even though the anchorPoint is left to the (.5, .5) default, it looks like the sprite gets bigger and moves to the right, as it is wasn't scaling relative to its center. I'm assuming I'm doing something wrong because if it sounds kind of silly to have to adjust the x,y to counter the effect of the scaling.

How do I accomplish scaling relative to its center?

Upvotes: 0

Views: 2718

Answers (1)

DogCoffee
DogCoffee

Reputation: 19966

This seems to work as expected

SKSpriteNode *myRec = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(40, 40)];
myRec.position = CGPointMake(150, 150);
[self addChild:myRec];

[myRec runAction:[SKAction repeatActionForever:[SKAction sequence:@[
                                     [SKAction waitForDuration:3.0],
                                     [SKAction scaleTo:2.0 duration:2.0],
                                     [SKAction scaleTo:1.0 duration:2.0],
                                     ]]]];

If your scaling a sprite, make sure the doesn't have extra transparent space off too one side.

Upvotes: 3

Related Questions