Author: Adam Buchweitz (email)
Version 1.1
Written and supported by Adam Buchweitz and Crawl Space Games
http://crawlspacegames.com http://twitter.com/crawlspacegames http://twitter.com/adambuchweitz
For inquiries about Crawl Space, email us at [email protected]
For support with this class, email me at [email protected]
Copyright (C) 2011 Crawl Space Games - All Rights Reserved
###:: FEATURES ::
This toggle is a simple toggle switch. It is capable of switching between two images, with or without dynamic resolution, and can also switch between two strings.
To toggle images, the only parameters needed are on and off images. To use dynamic resolution images, simply supply additional parameters for width and height.
To toggle strings, you have the option of supplying a font, a text size, and a text color.
The toggle switches via touch, but you can also set the state manually, and retrieve its state at any time.
Declare a default value with a 'state' parameter, and the method to fire with a 'callback' parameter.
Your "on" and "off" images or strings will likely be different widths or heights, so for visual display aid you may also assign a reference point.
###:: USAGE ::
ToggleClass.new( params )
###:: EXAMPLE :: ####Switch between two images
local toggle = require "toggle"
local myToggle = toggle.new( { on = "path/to/imageOn.png", off = "path/to/imageOff.png", callback = myFunction } )
###:: EXAPMLE :: ####Switch between two images with dynamic resolution, and default the state to off
local toggle = require "toggle"
local params = {
on = "path/to/imageOn.png",
onWidth = 100,
onHeight = 50,
off = "path/to/imageOff.png",
offWidth = 100,
offHeight = 50,
state = false,
callback = myFunction
}
local myToggle = toggle.new( params )
###:: EXAMPLE :: ####Switch between two centered strings with a custom font, size, and color
local toggle = require "toggle"
local params = {
onText = "On",
offText = "Off",
font = "Helvetica",
textSize = "24",
textColorOn = { 255, 0, 0 },
textColorOff = { 0, 255, 0 },
referencePoint = display.CenterReferencePoint,
callback = myFunction
}
local myToggle = toggle.new( params )
###:: EXAMPLE :: ####Change the VISUAL state manually, this does NOT fire the attached callback
myToggle.setState(true)
###:: EXAMPLE :: ####Change the state manually and fire its attached callback
myToggle.setState(true, true)