GetAlphaAtTime
This function returns an alpha value at specified time.
Syntax
- number GetAlphaAtTime(number time)
Parameters
- time: - a value between 0.0 and 1.0 corresponding to a particle's lifetime. 0.0 being birth and 1.0 being death.
Returns
This function returns a float containing the alpha value between 0.0 and 1.0, 0 being transparent and 1 being opaque.
Example
time = 0.5
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Create an emitter
emitter = Emitter:Create(100)
emitter:ClearAlphaControlPoints() --Remove default control points
emitter:AddAlphaControlPoint(0,0) --at spawn the particle will have an alpha of 0 (fully transparent)
emitter:AddAlphaControlPoint(.5,1) --halfway through the particle's lifetime alpha will be 1 (ie not transparent)
emitter:AddAlphaControlPoint(1,0) --at death the particle will be fully transparent
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()
if (window:KeyDown(Key.Up)) then
time = time + 0.01
elseif (window:KeyDown(Key.Down)) then
time = time - 0.01
end
time = math.max(0,time)
time = math.min(1,time)
context:SetBlendMode(Blend.Alpha)
context:DrawText("At "..(time*100) .. " percent of the particles life alpha will be :" .. emitter:GetAlphaAtTime(time) ,2,2)
context:Sync()
end