2013-12-12 87 views
3

我試圖在具有一個孩子, 所有的動作都在2個形狀除了一起執行一個SKSpriteNode運行SKActions的序列:調整大小SKSpriteNode與它的孩子

[SKAction resizeToWidth:<#(CGFloat)#> height:<#(CGFloat)#> duration:<#(NSTimeInterval)#>] 

這裏是我的代碼:

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

}

回答

9

要實現你應該使用scaling,而不是調整預期的效果。

替換:

SKAction *zoom=[SKAction group:[NSArray arrayWithObjects:[SKAction moveTo:CGPointMake(60, 345) duration:0.75],[SKAction resizeToWidth:80 height:80 duration:0.75], nil]]; 

有了:

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

下面的代碼應該工作你的情況:

-(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]; 
} 
} 
+0

感謝您的幫助:) –

+2

沒問題:)。還有一些語法糖,你可以用@代替[NSArray arrayWithObjects:...,nil]。 ;) –

相關問題