2013-11-05 117 views
2

我有一个SKSpriteNode开始透明,我想让它完全可见,从一侧开始移动到另一侧,以整个可见的精灵结束。 This question解决了UIViews上CALayers的问题,但似乎并不像我们可以访问SKSpriteNode的CALayers。SKSpriteNode动画渐变

有没有办法将动画渐变应用于SKSpriteNodes?

+0

你看着SKEffectNode:您可以通过Xcode的创建新的“SpriteKit游戏”项目,并在MyScene.m更换touchesBegan运行呢? – DogCoffee

回答

3

下面是如何使用裁剪节点进行操作的示例。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    /* Called when a touch begins */ 

    for (UITouch *touch in touches) { 
     CGPoint location = [touch locationInNode:self]; 

     SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"]; 

     SKCropNode *cropNode = [SKCropNode node]; 

     // maskNode is twice as big as the sprite: 
     // fully masked on the left, fully visible on the right 
     SKNode *masked = [SKSpriteNode spriteNodeWithColor:[SKColor clearColor] size:sprite.frame.size]; 
     SKNode *shown = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:sprite.frame.size]; 
     shown.position = CGPointMake(sprite.frame.size.width, 0); 

     SKNode *maskNode = [SKNode node]; 
     [maskNode addChild:masked]; 
     [maskNode addChild:shown]; 

     cropNode.maskNode = maskNode; 
     cropNode.position = location; 

     [self addChild:cropNode]; 
     [cropNode addChild:sprite]; 

     SKAction *fadeIn = [SKAction moveBy:CGVectorMake(-sprite.frame.size.width, 0) duration:5]; 
     [maskNode runAction:fadeIn]; 
    } 
} 
+0

这对我有用,谢谢! – Siegfoult