Reputation: 413
I am trying to run a sequence of SKActions on a SKSpriteNode which has one child, all the actions are performed on the 2 shapes together except :
[SKAction resizeToWidth:<#(CGFloat)#> height:<#(CGFloat)#> duration:<#(NSTimeInterval)#>]
Here is my code:
-(void)CreateCards{
for (int i=0; i<3; i++) {
SKSpriteNode *sprite=[SKSpriteNode spriteNodeWithImageNamed:@"default_circle.png"];
SKSpriteNode *shape=[SKSpriteNode spriteNodeWithImageNamed:[self GetRandomImage]];
[sprite addChild:shape];
sprite.position=CGPointMake(-43, 345);
sprite.size=CGSizeMake(43, 43);
shape.size=CGSizeMake(43, 43);
SKAction *zoom=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:CGPointMake(60, 345) duration:0.75],[SKAction resizeToWidth:80 height:80 duration:0.75], nil]];
zoom.timingMode=SKActionTimingEaseOut;
SKAction *zoomOut=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:[self GetLocationOfIndex:i NumberOfCircles:3] duration:0.5],[SKAction resizeToWidth:43 height:43 duration:0.5], nil]];
zoomOut.timingMode=SKActionTimingEaseIn;
SKAction *enter=[SKAction sequence:[NSArray arrayWithObjects:[SKAction waitForDuration:1*i],zoom,zoomOut, nil]];
[sprite runAction:enter];
[self addChild:sprite];
}
}
Upvotes: 3
Views: 5465
Reputation: 3102
To achieve the desired effect you should use scaling instead of resizing.
Replace:
SKAction *zoom=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:CGPointMake(60, 345) duration:0.75],[SKAction resizeToWidth:80 height:80 duration:0.75], nil]];
With:
SKAction *zoom=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:CGPointMake(60, 345) duration:0.75],[SKAction scaleXBy:80/43 y:80/43 duration:0.75], nil]];
Following code should work for your case:
-(void)CreateCards{
for (int i=0; i<3; i++) {
SKSpriteNode *sprite=[SKSpriteNode spriteNodeWithImageNamed:@"default_circle.png"];
SKSpriteNode *shape=[SKSpriteNode spriteNodeWithImageNamed:[self GetRandomImage]];
[sprite addChild:shape];
sprite.position=CGPointMake(-43, 345);
sprite.size=CGSizeMake(43, 43);
shape.size=CGSizeMake(43, 43);
CGFloat zoomScale = 80 / 43;
SKAction *zoom=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:CGPointMake(60, 345) duration:0.75],[SKAction scaleXBy:zoomScale y:zoomScale duration:0.75], nil]];
zoom.timingMode=SKActionTimingEaseOut;
SKAction *zoomOut=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:[self GetLocationOfIndex:i NumberOfCircles:3] duration:0.5],[SKAction scaleXBy:1.0f y:1.0f duration:0.5], nil]];
zoomOut.timingMode=SKActionTimingEaseIn;
SKAction *enter=[SKAction sequence:[NSArray arrayWithObjects:[SKAction waitForDuration:1*i],zoom,zoomOut, nil]];
[sprite runAction:enter];
[self addChild:sprite];
}
}
Upvotes: 9