2

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

我正在尝试为fillNodeSKCropNode ( cropNode) 的内容 ( ) 设置动画。下面的代码很好地设置了 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而不是它的子节点设置动画。

有什么想法我哪里出错了吗?

4

2 回答 2

5

如果有人想知道如何屏蔽,仅供参考,这是一个简单的片段

- (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]];
}
于 2013-10-08T21:37:03.607 回答
2

知道了!

[self.logoContent.target_illustration runAction: moveSequence completion:^{

应该

[self.logoContent.children[0] runAction: moveSequence completion:^{

我的插图现在按指示移动:)

于 2013-10-08T21:16:39.170 回答