在SpriteKit动画屏蔽的图像(SKCropNode) [英] Animate masked image in SpriteKit (SKCropNode)
问题描述
我用雪碧Kit创建我的第一个iOS应用程序,而我绊倒什么似乎是一个pretty基本问题。
I'm using Sprite Kit to create my first iOS app, and I'm stumbling over what seems to be a pretty basic problem.
我试图动画一SKCropNode的内容( fillNode
)( cropNode
)。下面的code树立SKScene就好了(我看到正确掩盖了说明,在正确的位置放置在背景图片)...
I'm trying to animate the contents (fillNode
) of a SKCropNode (cropNode
). The code below sets up the SKScene just fine (I see the illustration masked correctly, placed over the background image in the right location)...
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];
...但我不能访问被屏蔽的插图动画的位置(我想它的面具和幻灯片到位外开始):
...but I can't access the masked illustration to animate its position (I want it to start off outside the mask and slide into position):
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
,而不是它的子节点。
任何想法,我要去哪里错了?
Any ideas where I'm going wrong?
推荐答案
仅供参考,如果有人想知道如何掩盖,这里是一个简单的代码片段
Just for reference if anyone wants to know how to mask, here is a simple snippet
- (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]];
}
这篇关于在SpriteKit动画屏蔽的图像(SKCropNode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!