gpt4 book ai didi

animation - SpriteKit (SKCropNode) 中的动画蒙版图像

转载 作者:行者123 更新时间:2023-12-04 16:01:01 25 4
gpt4 key购买 nike

我正在使用 Sprite Kit 创建我的第一个 iOS 应用程序,但我遇到了一个看似非常基本的问题。

我正在尝试为 SKCropNode (cropNode) 的内容 (fillNode) 制作动画。下面的代码很好地设置了 SKScene(我看到插图被正确遮盖,放置在正确位置的背景图像上)...

SKSpriteNode *logoBG = [[SKSpriteNode alloc] initWithImageNamed:logoBackground];
logoBG.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:logoBG];

SKCropNode *cropNode = [[SKCropNode alloc] init];
cropNode.maskNode = [[SKSpriteNode alloc] initWithImageNamed:logoMask];
SKSpriteNode *fillNode = [[SKSpriteNode alloc] initWithImageNamed:logoImage];

[cropNode addChild:fillNode];
fillNode.position = CGPointMake(0,300);
cropNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
self.logoContent = cropNode;
[self addChild:self.logoContent];

...但我无法访问蒙版插图来为其位置设置动画(我希望它从蒙版外开始并滑入到位):

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;

SKAction *moveUp = [SKAction moveByX: 0 y: 100 duration: 5];
SKAction *moveSequence = [SKAction sequence:@[moveUp]];
[self.logoContent.target_illustration runAction: moveSequence completion:^{ // '.target_illustration' = the SKSpriteNode that I want to animate; cropNode.fillNode
SKScene *titleScreen = [[TitleScreen alloc] initWithSize:self.size];
SKTransition *fade = [SKTransition fadeWithDuration:(1)];
[self.view presentScene:titleScreen transition:fade];
}];

我只能为整个 logoContent 而不是它的子节点设置动画。

有什么地方出错了吗?

最佳答案

仅供引用,如果有人想知道如何屏蔽,这里有一个简单的片段

- (void) cropNodes
{
// the parent node i will add to screen
SKSpriteNode *picFrame = [SKSpriteNode spriteNodeWithColor:[SKColor greenColor] size:CGSizeMake(100, 100)];
picFrame.position = CGPointMake(200, 200);

// the part I want to run action on
SKSpriteNode *pic = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
pic.name = @"PictureNode";

SKSpriteNode *mask = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(80, 50)];

SKCropNode *cropNode = [SKCropNode node];
[cropNode addChild:pic];
[cropNode setMaskNode:mask];
[picFrame addChild:cropNode];
[self addChild:picFrame];

// run action in this scope
//[pic runAction:[SKAction moveBy:CGVectorMake(30, 30) duration:10]];

// outside scope - pass its parent
[self moveTheThing:cropNode];
}

- (void) moveTheThing:(SKNode *) theParent
{
// the child i want to move
SKSpriteNode *moveThisThing = (SKSpriteNode *)[theParent childNodeWithName:@"PictureNode"];
[moveThisThing runAction:[SKAction moveBy:CGVectorMake(30, 30) duration:10]];
}

关于animation - SpriteKit (SKCropNode) 中的动画蒙版图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19257923/

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