PlayerGfx.lua

From Moondust Wiki
Jump to navigation Jump to search

Download Latest Version

playerGfx is a library for swapping or overlaying sets of player graphics at runtime.

Installation

Drop the playerGfx.lua file in the LuaScriptsLib folder.

How to use

Overlay/replacement images should be formatted like regular SMBX player graphics, except they must be PNG files with transparent backgrounds and they should ideally use the naming convention "[prefix]_[number]" as opposed to SMBX's default "[prefix]-number". They should be placed in the episode or level folder.

Once you have your images in place, load in the API and use 'playerGfx.arrayFromPrefix()' to generate a table of your images' filenames. Use that table in PlayerGfxSet.create() to generate a PlayerGraphicsSet instance, and call playerGfx.assignSet() to assign a PlayerGraphicsSet to a given character.

Extra graphics sets are only used when playerGfx.isOn == true; use playerGfx.enable(), playerGfx.disable() and playerGfx.toggle() to activate and deactivate the system.

Code Documentation

playerGfx
Type Function/Field Return values/Value type Description
function .enable () nil Enables the graphic replacement system.
function .disable () nil Disables the graphic replacement system.
function .toggle () nil Toggles the graphic replacement system.
function myFilenameTable = .arrayFromPrefix (String prefix) Table of String Generates a table of filenames corresponding to powerup states from a given prefix using the format "[prefix]_[number].png".
function myPlayerGfx = PlayerGfxSet.create (Table of String filenameArray, number offsetX, number offsetY, boolean overwrite) nil Creates a new graphics set from the given filename array. When assigned to a player character, the images will be offset from the player's position by offsetX and offsetY, and if overwrite is true the player's normal graphics will be hidden.
function .assignSet (Character constant playerChar, PlayerGfxSet gfxSet) nil Changes the given player character's graphics to use the given PlayerGfxSet; if gfxSet is nil, the character is reset to their default graphics.