Fade.lua

From Moondust Wiki
Revision as of 12:51, 16 August 2015 by Kevsoft (talk | contribs)
Jump to navigation Jump to search

Download Latest Version

fade.lua is a small library for creating colored fading effects and colored overlays.

Installation

Copy the fade.lua file in the LuaScriptsLib folder.


How to use

To enable the fade library for a specific level, add this line to lunadll.lua:

local fade = loadAPI("fade");

This will load the Fade API.

Example

Simple Fade Effect

local fade = loadAPI("fade");

local myCustomFade = fade()
myCustomFade:setStart(255, 255, 255, 255)
myCustomFade:setEnd(255, 255, 255, 0)
myCustomFade:setTransitionTime(65*4)

function onLoad()
    myCustomFade:start()
end

This will create a fade effect which starts from full white to full opacity. If you want to, you can also use hex-values instead:

myCustomFade:setStart(0xFFFFFFFF)
myCustomFade:setEnd(0xFFFFFF00)

Simple Color Overlay

local fade = loadAPI("fade");

local myCustomOverlay = fade()
myCustomOverlay:setStart(0, 0, 255, 100)
myCustomOverlay:setEnd(0, 0, 255, 100)

function onLoad()
    myCustomOverlay:start()
end

This will create a blue overlay over the level.


Documentation

Fade API
Function Return values Description
myFade = fade() Fade object Sets the memory of the given type.


Fade object
Function Return values Description
FadeObj:setStart(int red, int green, int blue, int alpha) nil Sets the transition start color. (0-255)
FadeObj:setStart(int rgba) nil Sets the transition start color. (0 - 0xFFFFFFFF)
FadeObj:setEnd(int red, int green, int blue, int alpha) nil Sets the transition end color. (0-255)
FadeObj:setEnd(int rgba) nil Sets the transition end color. (0 - 0xFFFFFFFF)
FadeObj:setTransitionTime(int transitionTime) nil Sets the time how long the animation should take from the start color to the end color. The transition time equals the framerate of SMBX (65 = 1 second)
FadeObj:reset() nil Resets the current transition color to the start transition color
FadeObj:start() nil Resets and starts the transition animation.
FadeObj:pause() nil Pauses the transition animation. The current transition animation frame will be still displayed.
FadeObj:continue() nil Resumes the transition animation.
FadeObj:stop() nil Pauses the transtion animation. The current transtion animtion frame will NOT be displayed.
FadeObj:isFinished() boolean Returns true, if the animation finshed.