Fade.lua

From PGE Wiki
Jump to: navigation, search

Download Latest Version

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

Installation

Copy the fade.lua file into either your level's custom graphics folder for use in a level, along with a lunadll.lua file, or into the same directory as your .wld file along with a lunaworld.lua file for use throughout an entire episode.

How to use

To enable the fade library:

local fade = API.load("fade");

This will load the Fade API.

Examples

Simple Fade Effect

local fade = API.load("fade");

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

function onStart()
    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 = API.load("fade");

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

function onStart()
    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.
FadeObj.x number The x position of the fade animation. (Default 0)
FadeObj.y number The y position of the fade animation. (Default 0)
FadeObj.width number The width of the fade animation. (Default 800)
FadeObj.height number The height of the fade animation. (Default 600)