Andrewgosu
The Silent Pandaren Helper
- Reaction score
- 716
This is just a simple snippet/(mini) system which allows you to gradually "fade" units over time.
The argument list explanation:
An example call using GUI:
(Sorry for pseudo variable...)
N.B! Requires CSData and CSSafety (included in the demo map)
The code:
Anyway, feedback is appreciated!
And, as always, happy mapping!
Andrewgosu
The argument list explanation:
function UnitFadeTransparency takes unit whichUnit, real duration, real startTrans, real endTrans returns nothing
- unit whichUnit - the unit you want to fade
- real duration - the time it takes to fade the unit
- real startTrans - the start transparency in %. (100 for fully visible)
- real endTrans - the end transparency in % (0 for fully invisible)
- unit whichUnit - the unit you want to fade
- real duration - the time it takes to fade the unit
- real startTrans - the start transparency in %. (100 for fully visible)
- real endTrans - the end transparency in % (0 for fully invisible)
An example call using GUI:
Trigger:
- Actions
- Set period = (Random real number between 3.00 and 5.00)
- Set endTrans = (Random real number between 0.00 and 50.00)
- Custom script: call UnitFadeTransparency(udg_tmpUnit , udg_period, 100 ,udg_endTrans)
(Sorry for pseudo variable...)
N.B! Requires CSData and CSSafety (included in the demo map)
The code:
JASS:
library UNITFADE
//ver 1.0
globals
private constant real TIMER_VAL = 0.03125
endglobals
private struct fadeinfo
unit fadeWhich
real transAdd
real transCur = 0
integer trans
real ticks = 0
real ticksEnd
endstruct
private function fadeunit_callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local fadeinfo data = GetCSData(t)
set data.ticks = data.ticks + 1
if (data.ticks <= data.ticksEnd) then
set data.transCur = data.transCur + data.transAdd
if (data.transCur <= -1) then
set data.transCur = data.transCur + 1
set data.trans = data.trans - 1
call SetUnitVertexColor(data.fadeWhich, 255, 255, 255, data.trans)
else
set data.transCur = data.transCur + 1
set data.trans = data.trans + 1
call SetUnitVertexColor(data.fadeWhich, 255, 255, 255, data.trans)
endif
else
call data.destroy()
call ReleaseTimer(t)
endif
endfunction
private function fadeunit_exec takes unit whichUnit, real period, real startTrans, real endTrans returns nothing
local timer t = NewTimer()
local fadeinfo data = fadeinfo.create()
set data.fadeWhich = whichUnit
set data.transAdd = ((endTrans - startTrans) * TIMER_VAL / period) * 2.55
set data.trans = R2I(startTrans * 2.55)
set data.ticksEnd = (period * RAbsBJ(data.transAdd) / TIMER_VAL)
call SetCSData(t, data)
call TimerStart(t, TIMER_VAL, true, function fadeunit_callback)
endfunction
function UnitFadeTransparency takes unit whichUnit, real duration, real startTrans, real endTrans returns nothing
call fadeunit_exec.execute(whichUnit, duration, startTrans, endTrans)
endfunction
endlibrary
Anyway, feedback is appreciated!
And, as always, happy mapping!
Andrewgosu