目标c – 动画SKScene的背景颜色

你会如何设计SKScene的背景颜色? 我尝试了UIView动画,但不出意外它没有用。 在Sprite-Kit中是否有相同的function?

我正在寻找类似的东西,但对于Sprite-Kit:

[UIView animateWithDuration:0.25 animations:^{ self.backgroundColor = [UIColor redColor]; }]; 

目前,作为一个解决方案,我已经在SKView上覆盖了一个UIView,但我想要一些更灵活的东西。

我对Sprite-Kit比较陌生,所以如果这非常简单,那就很有用了!

目前我有:

 -(id) initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { _bg = [SKSpriteNode spriteNodeWithColor:[SKColor colorWithRed:0.13 green:0.13 blue:0.13 alpha:1] size:self.size]; _bg.position = CGPointMake(self.size.width/2, self.size.height/2); [self addChild:_bg]; } return self; } -(void) colorise :(UIColor*)color { [_bg runAction:[SKAction colorizeWithColor:color colorBlendFactor:_bg.colorBlendFactor duration:1]]; } 

在初始化SKView之后,我根据NSUserDefault值设置bg精灵的颜色。

  if ([[NSUserDefaults standardUserDefaults] integerForKey:@"currGameMode"] == 0) { ((bubbleAnimation2*)_bubbleEffectView.scene).bg.color = [UIColor colorWithRed:0.13 green:0.13 blue:0.13 alpha:1];} else {((bubbleAnimation2*)_bubbleEffectView.scene).bg.color = [UIColor colorWithRed:0.25 green:0.13 blue:0.13 alpha:1];} 

谢谢!

好吧,我提出了一个完全过度设计的解决方案! 我有一系列背景精灵,我克隆原始精灵并改变它的颜色,然后将其设置为动画。

这是我的代码:

 -(void) colorise :(UIColor*)color { // [_bg runAction:[SKAction colorizeWithColor:color colorBlendFactor:_bg.colorBlendFactor duration:1]]; if ([_bgObjects count] != 0) { SKSpriteNode* newBg = [[_bgObjects objectAtIndex:0] copy]; newBg.color = color; newBg.alpha = 0; [self insertChild:newBg atIndex:1]; [newBg runAction:[SKAction fadeAlphaTo:1 duration:0.5]]; [_bgObjects addObject:newBg]; for (int i = 0; i < ([_bgObjects count]-1); i++) { [[_bgObjects objectAtIndex:i] runAction:[SKAction fadeAlphaTo:0 duration:0.5]]; } } } -(void) update:(NSTimeInterval)currentTime { if ([_bgObjects count] > 1) { NSMutableArray* toDelete = [NSMutableArray arrayWithObjects: nil]; for (SKSpriteNode* bg in _bgObjects) { if ((bg.alpha == 0) && !bg.hasActions) { [bg removeFromParent]; [toDelete addObject:bg]; }} [_bgObjects removeObjectsInArray:toDelete]; } }