buttonMaker.lua

All starter kits/packages come with the module file easy/buttonMaker.lua.

This is a very basic button creating library that allows you to, predefine buttons, then use those 'presets' to make:

Using Button Maker

This video demonstrates how fast an easy it is to make snazy looking buttons with the preset concept and the buttonMaker module.

Starters Core - Button Maker

Basic Usage

local buttonMaker = require "easy.buttonMaker"

version()

Prints out and returns the current version of the buttonMaker module in the format YYMMDD.

addPreset( name, def )

Adds a new preset definion def to the prests library.

See easyPush below for a full list of preset fields and their purpose.

local default = 
{ 
   selImg           = "easy/fillW.png",
   selColor         = { 0.5, 0.5, 0.5 },
   selLabelColor    = { 0.125, 0.125, 0.125 },

   unselImg         = "easy/fillW.png",
   unselColor       = { 0.25, 0.25, 0.25 },
   unselLabelColor  = { 1, 1, 1 },

   font             = native.systemFont,
   fontSize         = 32,
   labelOffset      = { 0, 0 },
}

buttonMaker.addPreset( "default", default )

getPreset( name )

Returns the definition of a named preset. This is handy if you want to use an existing preset to create a new one. Just get the existing one and modify the parameters you want to change.

local default = buttonMaker.getPreset( "default" )

default.font     = native.systemFontBold
default.fontSize = 40

buttonMaker.addPreset( "big_default", default )

easyPush( params )

Makes a preset based push button using a table of optional parameters.

With the exception of parent, preset, x, y, labelText, and listener, all of the following fields are also valid preset fields.

Passing these fields in your params table will override any preset field the requested preset may have set.

local function onPush( self, event )
   -- Do something here
end

Examples

Play Button

local onPlay = function( self, event )
   composer.gotoScene( "scenes.play", { time = 500, effect = "crossFade" } )
end

buttonMaker.easyPush( { preset = "play", x = centerX, y = centerY, 
                        listener = onPlay } )

Restore IAP Button

local function restoreIAP()
   _G.easyIAP.restore()
end

buttonMaker.easyPush( { labelText = "Restore IAP", fontSize = 22, 
                        x = left + 80, y = bottom - 140, 
                        width = 140, height = 60, 
                        listener = restoreIAP } )

easyToggle( params )

Makes a preset based toggle button using a table of optional parameters.

Takes same parameters as easyPush()

The returned button object has a toggle function that can be used to toggle the button ON. Calling this does NOT call the listener. It only sets the 'toggled' state of the button to true.

easyRadio( params )

Makes a preset based radio button using a table of optional parameters.

Takes same parameters as easyPush()

The returned button object has a toggle function that can be used to toggle the button ON. Calling this does NOT call the listener. It only sets the 'toggled' state of the button to true.


RoamingGamer Copyright © Roaming Gamer, LLC. 2008-2018; All Rights Reserved