- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的触摸开始方法中,我放置了这行简单的代码,它将背景颜色淡化为红色。
runAction(SKAction.colorizeWithColor(SKColor.redColor(), colorBlendFactor: 1.0, duration: 1.0))
最佳答案
有多种方法可以从一种颜色过渡到另一种颜色。最直接的方法之一是在两种颜色之间进行线性插值,方法是将逐渐增大的起始颜色的 RGB 分量与逐渐减小的结束颜色的 RBG 分量相结合:
red = starting_red * (1.0 - fraction) + ending_red * fraction
green = starting_green * (1.0 - fraction) + ending_green* fraction
blue = starting_blue * (1.0 - fraction) + ending_blue * fraction
fraction
从 0 开始到 1 结束,增量为
fraction += delta_time * step_size
didMoveToView
GameScene
的方法.但是,如果您的游戏包含多个场景,更好的策略是扩展
SKAction
添加一个创建自定义 Action 的类方法,以便所有场景都可以使用它。
GameScene
的定义之外.
struct ColorComponents {
var red:CGFloat
var green:CGFloat
var blue:CGFloat
init(color:SKColor) {
self.init()
var alpha:CGFloat = 0
color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
}
init() {
red = 0
green = 0
blue = 0
}
}
SKAction
通过添加以下方法将背景颜色更改为另一种颜色。请注意,扩展必须在类之外定义。
extension SKAction {
static func changeColor(startColor:SKColor, endColor:SKColor, duration:NSTimeInterval) -> SKAction {
// Extract and store starting and ending colors' RGB components
let start = ColorComponents(color: startColor)
let end = ColorComponents(color: endColor)
// Compute the step size
let stepSize = CGFloat(1/duration)
// Define a custom class to gradually change a scene's background color
let change = SKAction.customActionWithDuration(duration) {
node, time in
let fraction = time * stepSize
let red = start.red * (1.0 - fraction) + end.red * fraction
let green = start.green * (1.0 - fraction) + end.green * fraction
let blue = start.blue * (1.0 - fraction) + end.blue * fraction
if let scene = node as? SKScene {
scene.backgroundColor = SKColor(red: red, green: green, blue: blue, alpha: 1.0)
}
}
return change
}
}
SKAction
runAction(SKAction.changeColor(backgroundColor, endColor: SKColor.blueColor(), duration: 5))
didMoveToView
在您的
SKScene
子类,例如
GameScene
.
关于sprite-kit - 将背景颜色淡化为另一种颜色的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34938890/
我有一些 div 垂直对齐内部的 display: table 和 display: table-cell。无论如何,问题是,当我通过 fadeTo() 或 fadeIn 使用 jQuery 设置不透
使用 jQuery,我想在“框”中循环显示 3 个不同的背景图像和 3 组文本,每 6 秒淡出到下一个。 CSS: .box { background: url(/filepath/to/image.
点击背景更改为图像或颜色。为此,首先我为 body 创建了两个类: body.bg-color { background-color:red; } body.bg-img { back
正如标题所说,我想要实现的是在 "Patch "+ $Patch_next 字符串中淡入淡出,而不是在悬停时立即显示它。 if(isset($Patch_next)){
我正在创建一个导航并且已经为按钮制作了 CSS 属性。 我想在静态按钮属性之上淡入悬停属性。 这样做最有效的方法是什么? CSS 看起来像这样: Home
我已经能够淡化 div 的顶部,但我无法让底部也淡化。我想我可以反转我用来淡化顶部的 css,但它不起作用。 HTML: LOCATIONS CSS .contai
我想创建一个特定大小的列表,但它的内容可能比列表大。 我认为如果列表中有元素并且它们在底部和顶部淡出,同时为也包含该列表的容器提供背景图像,那将会非常漂亮。事实证明,这比预期的要难,而且我很难为此类事
我对我的问题做了一些研究,不幸的是我的问题没有解决方案。最接近的是 Fade UIImageView as it approaches the edges of a UIScrollView但它仍然不
大家好,我在淡出 HTML 文档中的 Div 时遇到了问题。我能够使用相反的相同功能,并且能够根据需要淡入但不能淡出 div。有什么想法吗? 这是 JavaScript 函数: function fa
我对 Java 和 SWT 还很陌生,希望能将一幅图像融入到另一幅图像中。我现在在标签中有一张图片(相关代码): Device dev = shell.getDisplay(); try {
这个问题在这里已经有了答案: How to set gradient color to the background of UILabel in iPhone (2 个答案) 已关闭 8 年前。
我想下载 zip 并解压。当我下载 zip 时,一切正常。但是,当解压缩时,我的界面会停止几秒钟,有时应用程序会崩溃。如何解决? Zip 文件大小 650 MB downloadButton - 单击
我想使用 jquery 淡入一个 div,但它不起作用。如果我将“fout”(这是我想要淡入的元素)的可见性设置为隐藏,那么它不会显示任何内容,尽管消息仍然存在,因为我可以看到滚动条在移动。知道为什么
我目前有一个填充了用户 friend 的 tableView。 tableView 是 TableViewController 的一部分,它可以正常运行。我希望 tableview 在最底部永久淡化,
我有一个我正在尝试构建的 CSS 下拉菜单,下拉菜单的背景有一个褪色/锥形框阴影: 我无法实现如何让方框阴影真正变细/淡出。 这是我现在所在的位置:http://jsfiddle.net/Shpigf
我正在寻找一种在 Unity 中淡化 TextMesh-Text 的 alpha 值的方法,但我无法在线找到解决方案,也无法在 LeanTween Documentation 中找到解决方案。 . L
如何使用 jQuery 淡化 div 的边缘?想象一个内部有图像的旋转木马,可以水平滑动。如何淡出左右两侧,使边缘附近的图像逐渐消失。 希望它是清楚的。 :) 最佳答案 Webkit 浏览器(即 Ch
我发现与 Javascript 无关的默认智能感知建议。 native 浏览器功能太多I will never use . 有没有办法关闭/限制智能感知?例如隐藏浏览器方法,如上面链接中的方法。 最佳
我正在尝试淡出 detailView 中 UIWebView 的底部。它更像是褪色最后 20-40 像素。我正在为“ReadMoreFade”(link)使用 CSSTricks 代码。下面粘贴了我的
我想创建一个显示成功消息的模态弹出窗口(针对移动设备)。 我目前正在为整个内容添加一个不透明的背面叠加层,使用 .overlay { position:fixed; top:0px;
我是一名优秀的程序员,十分优秀!