the common.lua (the one with sidebar code)
[lua]
local scrollView
local icons = {}
local widget = require(“widget”)
local icon1,icon2,icon3,icon4,buttonSideBar
local composer = require(“composer”)
local scene = composer.newScene()
local isPlayingMusic = true
local bgTune = audio.loadStream(“sape.mp3”)
local function iconListener1( event )
if ( event.phase == “moved” ) then
local dx = math.abs(event.x - event.xStart )
if ( dx > 5 ) then
scrollView:takeFocus( event )
end
elseif ( event.phase == “ended” ) then
print (“Go to scene menu from sidebar”)
composer.gotoScene(“menu”)
timer.performWithDelay( 10, function() scrollView:removeSelf(); scrollView = nil; end )
print (“Close sidebar”)
end
return true
end
local function iconListener2( event )
if ( event.phase == “moved” ) then
local dx = math.abs(event.x - event.xStart )
if ( dx > 5 ) then
scrollView:takeFocus( event )
end
elseif ( event.phase == “ended” ) then
print (“Go to scene about Museum”)
composer.gotoScene(“aboutMuseum”)
timer.performWithDelay( 10, function() scrollView:removeSelf(); scrollView = nil; end )
print (“Close sidebar”)
end
return true
end
local function iconListener3( event )
if ( event.phase == “moved” ) then
local dx = math.abs(event.x - event.xStart )
if ( dx > 5 ) then
scrollView:takeFocus( event )
end
elseif isPlayingMusic then
print (“Music is playing”)
audio.stop()
print (“Stop the music”)
icon3.isVisible = false
icon4.isVisible = true
print (“Set icon mute invisible, icon play visible”)
else
audio.play( bgTune, {loops = -1} )
print (“Music is not playing, play the music”)
icon3.isVisible = true
icon4.isVisible = false
print (“Set icon play invisible, icon mute visible”)
end
--toggle the boolean
isPlayingMusic = not isPlayingMusic
print (“Change is Playing to not Playing”)
timer.performWithDelay( 10, function() scrollView:removeSelf(); scrollView = nil; end )
print (“Close sidebar”)
return true
end
local function showSlidingMenu( event )
if ( “ended” == event.phase ) then
scrollView = widget.newScrollView
{
width = 100,
height = 1000,
scrollWidth = 100,
scrollHeight = 960,
horizontalScrollDisabled = true
}
scrollView.x = 26
scrollView.y = 500
local scrollViewBackground = display.newImage( “image/bar.jpg”,150,960)
scrollViewBackground.x = 50
scrollViewBackground.y = 480
scrollView:insert( scrollViewBackground )
--generate icons
icon1 = widget.newButton
{ defaultFile = (“image/map.jpg”),
width = 100, height = 100,
x = 70,y = 120,
fontSize = 30,
onEvent = iconListener1
}
icon2 = widget.newButton
{ defaultFile = (“image/info.jpg”),
width = 100, height = 100,
x = 70,y = 250,
onEvent = iconListener2
}
icon3 = widget.newButton
{ defaultFile = (“image/on.jpg”),
width = 100, height = 100,
x = 70,y = 380,
onEvent = iconListener3
}
icon4 = widget.newButton
{ defaultFile = (“image/mute.jpg”),
width = 100, height = 100,
x = 70,y = 380,
onEvent = iconListener3
}
scrollView:insert(icon1);
scrollView:insert(icon2);
scrollView:insert(icon3);
scrollView:insert(icon4);
end
return true
end
buttonSideBar = widget.newButton{
defaultFile = (“image/side.jpg”),
width = 100, height = 100,
x = 50, y = 50,
onEvent = showSlidingMenu
}
[/lua]
main.lua:
[lua]display.setStatusBar( display.HiddenStatusBar )
local composer = require (“composer”)
composer.gotoScene(“titleScreen”)
print (“Go to splashscreen”)
require “common”[/lua]
