Rob,
Already sent this to Dave privately but thought I’d go ahead and share it here too. To implement a common UI interface in my scenes I include the following lines in each scene:
local ui = require( "uiExample" ) local uiGroup = display.newGroup() ui.drawUI( uiGroup ) sceneGroup:insert( uiGroup )
And here’s a stripped down version of the module I used. I included an example of using the current scene to customize the behavior in the Back button listener.
Josh
----------------------------------------------------------------------------------------- -- -- uiExample.lua -- -- Functions used for drawing the user interface buttons such as back, help, etc. -- ----------------------------------------------------------------------------------------- local \_ = {} local composer = require( "composer" ) local widget = require( "widget" ) local options ={ effect = "fade", time = 400, } -- 'onRelease' event listener for backBtn local function onBackBtnRelease(event) local currScene = composer.getSceneName( "current" ) -- go to selected scene if currScene == "Play" then composer.gotoScene( "Menu", options ) elseif currScene == "Puzzle" then composer.gotoScene( "Play", options ) end return true -- indicates successful touch end -- 'onRelease' event listener for optionsBtn local function onOptionsBtnRelease(event) composer.gotoScene( "Options", options ) return true -- indicates successful touch end -- 'onRelease' event listener for storeBtn local function onStoreBtnRelease(event) composer.gotoScene( "Store", options ) return true -- indicates successful touch end function \_.drawUI(uiGroup) local options = { labelColor = { default={1}, over={0.25} }, font = native.systemFont, fontSize = 12, width=0.1\*display.contentWidth, height=0.1\*display.contentWidth, } options.label = "Options" options.x = 0.25\*display.contentWidth options.y = 0.5\*display.contentWidth options.onRelease = onOptionsBtnRelease local optionsBtn = widget.newButton( options ) uiGroup.optionsBtn = optionsBtn uiGroup:insert(optionsBtn) options.label = "Back" options.x = 0.5\*display.contentWidth options.y = 0.5\*display.contentWidth options.onRelease = onBackBtnRelease local backBtn = widget.newButton( options ) uiGroup.backBtn = backBtn uiGroup:insert(backBtn) options.label = "Store" options.x = 0.75\*display.contentWidth options.y = 0.5\*display.contentWidth options.onRelease = onStoreBtnRelease local storeBtn = widget.newButton( options ) uiGroup.storeBtn = storeBtn uiGroup:insert(storeBtn) return end return \_