ParalX.lua
Revision as of 05:12, 28 January 2016 by Rockythechao (talk | contribs)
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 paralX.create (table properties) to make Parallax layer objects.
Example
The following code was taken from this example level:
local 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 = paralX.create ({image=fg0Img, y=-360, priority=-1, repeatY=false, paralXX=1.45, paralXY=1.25})
fg1 = paralX.create ({image=fg1Img, x=-80, y=-780, priority=-0.5, repeatX=false, repeatY=false, paralXX=2, paralXY=1.5, alpha=0.5})
bg0 = paralX.create ({image=bg0Img, y=-80, priority=-96, repeatY=false, paralXX=0.6, paralXY=0.6})
bg1 = paralX.create ({image=bg1Img, x= 80, y=-60, priority=-96.2, repeatY=false, paralXX=0.45, paralXY=0.35, alpha=0.8})
pyramidBg = paralX.create ({image=pyramidBgImg, x=1464, y=-120, priority=-96.1, repeatX=false, repeatY=false, paralXX=0.55, paralXY=0.5})
cloudBg = paralX.create ({image=cloudBgImg, y=-80, priority=-96.3, repeatY=false, paralXX=0.125, paralXY=0.125, speedX=0.0625})
skyBg = paralX.create ({image=skyBgImg, y= 00, priority=-96.4, repeatX=false, repeatY=false, paralXX=0, paralXY=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 | paralX.create (table properties) | nil | Creates a new parallax layer with its' properties defined via named arguments. |
Properties
The following properties can be both defined in paralX.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 its' 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. |
| parallaxX | 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. |
| parallaxY | 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. |