• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Fade System

  • Like
Reactions: deepstrasz
Simple fade system written in wurst.
Fades a unit in/out over X seconds.
Intended for cinematic use, but could be used when a unit dies in a TD for example.

API:

yourUnit.fadeOut(duration)
yourUnit.fadeIn(duration)​

a3cb6d7c951902d19bfa3ee32d3af168.gif


Wurst:
package Fade

import TimerUtils
import LinkedListModule

timer t

public enum fadetype
    IN
    OUT

public function unit.fade(fadetype ft, real duration)
    new Fade(this, ft, duration)

public function unit.fadeOut(real duration)
    this.fade(fadetype.OUT, duration)

public function unit.fadeIn(real duration)
    this.fade(fadetype.IN, duration)

function unit.setFade(integer raw)
    this.setVertexColor(colorA(255,255,255, raw))

public class Fade
    use LinkedListModule
    unit fader
    real changeSpeed
    real fadeState
    construct(unit u, fadetype ft, real duration)
        changeSpeed = (255 / duration) * 0.03

        if(ft == fadetype.IN)
            changeSpeed *= -1
            fadeState = 0
        else
            fadeState = 255

        fader = u

function onLoop()
    Fade current = Fade.first
    while(current != null)
        current.fadeState -= current.changeSpeed
        current.fader.setFade(R2I(current.fadeState))
        if(current.fadeState >= 255 or current.fadeState <= 0)
            Fade next = current.next
            destroy current
            current = next
        else
            current = current.next

init
    t = getTimer()
    t.startPeriodic(0.03, function onLoop)
Wurst:
package Demo

import Fade
import TimerUtils

boolean tracker = false
unit test
real speed = 1

init
test = createUnit(players[0], 'Hpal', vec2(0, 0), angle(0))

test.fadeOut(speed)

getTimer()
..startPeriodic(speed, () -> begin
if(tracker)
test.fadeOut(speed)
tracker = false
else
test.fadeIn(speed)
tracker = true
end)
Contents

Fade System (Map)

Reviews
MyPad
Nitpicks: Since there are quite some Fade Systems already made for users here, it would affect the overall rating. A bit of documentation goes a long way. Notes: None Quirks: I like how short this system is, compared to other Fade systems...

Nitpicks:

  • Since there are quite some Fade Systems already made for users here, it would affect the overall rating.
  • A bit of documentation goes a long way.

Notes:

  • None

Quirks:

  • I like how short this system is, compared to other Fade systems.
  • Since there are no Wurst equivalents of Fade Systems as far as I know, this could affect my rating.

Status:


This resource has been Approved.
 
Top