gpt4 book ai didi

ios - 用它的 child 调整 SKSpriteNode 的大小

转载 作者:可可西里 更新时间:2023-11-01 06:23:15 26 4
gpt4 key购买 nike

我正在尝试在有一个子节点的 SKSpriteNode 上运行一系列 SKActions,所有 Action 都在 2 个形状上一起执行,除了:

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

最佳答案

要达到预期效果,您应该使用 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];
}
}

关于ios - 用它的 child 调整 SKSpriteNode 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20537875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com