我目前正在为 Roblox 的PointLight对象编写方法。目前我正在编写方法来增加和减少Brightness
PointLight 的属性,但我已经靠在墙上试图获得我需要的公式。
程序需要在 DarkenSpeed(2 秒)的范围内从 Brightness (1) 循环到 FadedBrightness (.3)。我已经尝试在谷歌上搜索可能的解决方案,但我担心我正在寻找的东西太具体了。
这是一个代码片段:
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
如果有任何更好的方法来实现这一点——或者甚至是不同的方法——我会全力以赴。我倾向于用我的代码获得隧道视野,除了当前的问题之外,我没有考虑任何其他事情。