【发布时间】:2017-01-09 14:24:05
【问题描述】:
我尝试过的解决方案:
Gradually change background color in Swift
Swift : Background Color fading animation (SpriteKit)
我目前拥有的(不工作):
class GameScene: SKScene, SKPhysicsContactDelegate{
var background = SKSpriteNode()
var colorizeToRed = SKAction()
override func didMoveToView(view: SKView) {
background = SKSpriteNode(color: UIColor.blueColor(), size: self.frame.size)
background.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
background.zPosition = 15
colorizeToRed = SKAction.colorizeWithColor(SKColor(red: 90, green: 0, blue: 0, alpha: 1), colorBlendFactor: 1.0, duration: 2.0)
background.runAction(colorizeToRed)
}
}
我的问题:
我没有看到背景改变颜色。我唯一看到它改变颜色的情况是,如果我使用 self.backgroundColor = UIColor().aColor 直接设置它而不使用动画。
编辑:事实上,我什至看不到蓝色背景...我的 SKSpriteNode 出了点问题,但是什么?
问题:
如何在 Spritekit 中逐渐(动画)改变背景颜色?
问之前:
1) 是的,我已经尝试更改 zPosition 以防 SKNode 被隐藏。
2) 是的,我已经检查了SKAction.colorizeWithColor() 的文档。
3) 是的,我几乎可以肯定我的问题的解决方案非常简单(可能是我的一些错误),但是呢?
4) 是的,我愿意接受任何告诉我错误在我的代码中的其他地方的建议,但前提是您要准确说明错误可能在哪里。
5) 不,我不会在这里发布我的整个代码,如有需要,请询问具体部分。
提前感谢您提供的任何帮助^^!
【问题讨论】:
标签: ios swift animation sprite-kit background-color