【发布时间】:2014-06-26 14:09:47
【问题描述】:
我目前正在为 Roblox 的 PointLight 对象编写方法。目前,我正在编写方法来增加和减少 PointLight 的 Brightness 属性,但我已经靠在墙上试图获得我需要的公式。
程序需要在 DarkenSpeed(2 秒)的范围内从 Brightness (1) 循环到 FadedBrightness (.3)。我已经尝试在谷歌上搜索可能的解决方案,但我担心我正在寻找的内容过于具体。
这是一个代码sn-p:
local LightSource = {
-- The value the PointLight's Brightness property will be when night and day,
-- respectively.
Brightness = 1,
FadedBrightness = .3,
-- How long (in seconds) it takes for the light source's brightness to be
-- faded in/out.
BrightenSpeed = 2,
DarkenSpeed = 2
}
-- There is an IncreaseBrightness method, but that should be easy enough to
-- modify once the below is working.
function LightSource:DecreaseBrightness()
-- self.Light refers to the PointLight instance.
-- light.Brightness would be the current `Brightness` property.
local light = self.Light
-- Need to combine Brightness, FadedBrightness and DarkenSpeed into a formula
-- for decrementing.
local decrement = self.FadedBrightness / (self.Brightness * self.DarkenSpeed) -- 0.15, that won't work at all.
while light.Brightness >= self.FadedBrightness do
light.Brightness = light.Brightness - decrement
wait()
end
end
如果有任何更好的方法来实现这一点 - 甚至是不同的方法 - 我会全力以赴。我倾向于用我的代码获得隧道视野,除了当前的问题之外,我没有考虑任何其他事情。
【问题讨论】:
-
您最大的问题是试图弄清楚如何在 2 秒内传播它?脚本环境中是否有任何类型的计时器/延迟功能?例如
delayfunction( 500, myfunc) -- execute myfunc after 500ms? -
啊,我看到 wait() 是 Roblox 的收益函数。
-
是的。让它持续达到 FadedBrightness 更多的是事后考虑,因为如果循环结束,我可以在循环之后设置
Brightness属性——尽管这可能会导致一些视觉上的混乱。 -
这个问题似乎是题外话,因为它是关于Code Review
-
@hjpotter92 哎呀!对于那个很抱歉。我会看到有关编辑帖子或在那里重新发布的信息。感谢您的提醒。