ParalX.lua

From PGE Wiki
Revision as of 03:44, 24 January 2016 by Rockythechao (talk | contribs) (Created page with "Category:LunaLua helper libraries [https://dl.dropboxusercontent.com/u/12431097/paralX.lua Download Latest Version] ParalX is a LunaLua library designed to create parall...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Download Latest Version

ParalX is a LunaLua library designed to create parallax background layers in Super Mario Bros X.

Installation

Place the file paralX.lua into the LuaScriptsLib folder. (Please note that this library relies on both Graphics.draw and the new rendering priorities which, as of writing this, are only available in development builds of LunaLua.)

How to use

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

local paralX = loadAPI("paralX");

This will load the ParalX API. From there, you can use Parallax.create (table properties) to make Parallax layer objects.

Example

The following code was taken from this example level:

paralX = loadSharedAPI("paralX")


-- Load the images
local fg0Img = Graphics.loadImage("fg0.png")
local fg1Img = Graphics.loadImage("fg1.png")

local bg0Img = Graphics.loadImage("bg0.png")
local bg1Img = Graphics.loadImage("bg1_alpha.png")
local pyramidBgImg = Graphics.loadImage("bg2.png")
local cloudBgImg = Graphics.loadImage("bg3_trans.png")
local skyBgImg = Graphics.loadImage("bg4.png")


-- Create the layers
function onStart ()
	fg0       = Parallax.create ({image=fg0Img,                  y=-360,   priority=-1,                      repeatY=false,   panRateX=1.45,   panRateY=1.25})
	fg1       = Parallax.create ({image=fg1Img,        x=-80,    y=-780,   priority=-0.5,   repeatX=false,   repeatY=false,   panRateX=2,      panRateY=1.5,     alpha=0.5})
	
	bg0       = Parallax.create ({image=bg0Img,                  y=-80,    priority=-96,                     repeatY=false,   panRateX=0.6,    panRateY=0.6})
	bg1       = Parallax.create ({image=bg1Img,        x= 80,    y=-60,    priority=-96.2,                   repeatY=false,   panRateX=0.45,   panRateY=0.35,    alpha=0.8})

	pyramidBg = Parallax.create ({image=pyramidBgImg,  x=1464,   y=-120,   priority=-96.1,  repeatX=false,   repeatY=false,   panRateX=0.55,   panRateY=0.5})
	cloudBg   = Parallax.create ({image=cloudBgImg,              y=-80,    priority=-96.3,                   repeatY=false,   panRateX=0.125,  panRateY=0.125,   speedX=0.0625})
	skyBg     = Parallax.create ({image=skyBgImg,                y= 00,    priority=-96.4,  repeatX=false,   repeatY=false,   panRateX=0,      panRateY=0})
end

function onLoop ()
	pyramidBg.y = -120 + 32*math.sin (os.clock())
end


Documentation

Functions

cinematX coroutine functions
Type Function/Field Return values/Value type Description
function Parallax.create (table args) nil Creates a new parallax layer with its' properties defined via named arguments.


Properties

The following properties can be both defined in Parallax.create (args) and accessed via parallaxObj.propertyName:

Name Type Is Optional? Default Value Description
image LuaImageResource no nil The image used; animations can be used as vertical sheets, though the frames property will need to be set accordingly (see below).
frames number yes 1 The number of frames in the animation.
animSpeed number yes 0.05 The rate at which the layer cycles through the frames of animation.
alpha number yes 1 The transparency of the layer; 0 = invisible, 1 = completely opaque
sections table of number yes {1, 2... 21} The sections in which the parallax layer is shown.
priority number yes -96 The depth at which the layer is shown; see this list for the sorting order.
x number yes 0 The horizontal offset of the layer.
y number yes 0 The vertical offset of the layer.
panRateX number yes 0.75 The rate at which the layer pans horizontally with the camera; 0 = fixed position on the screen, 1 = pans with the level, >1 = pans more than the level, <0 = pans in reverse.
panRateY number yes 0.75 The rate at which the layer pans vertically with the camera; 0 = fixed position on the screen, 1 = pans with the level, >1 = pans more than the level, <0 = pans in reverse.
speedX number yes 0 The horizontal speed of the layer independent of panning.
speedY number yes 0 The vertical speed of the layer independent of panning.
repeatX boolean yes true if true, the image is tiled horizontally.
repeatY boolean yes true if true, the image is tiled vertically.
gapX number yes 0 The horizontal separation between tiles.
gapY boolean yes 0 The vertical separation between tiles.