Hello can someone help me with my coding? I am trying to insert scrolling in a page for my application and it doesn’t seemed to work at all. Following is the code that i attempted to add scrolling function.
------------------------------------------------------------------- -- CoolHouse.lua ------------------------------------------------------------------- local composer = require( "composer" ) local widget = require ( "widget" ) local scene = composer.newScene() -- forward declarations and other locals local background local swipeThresh = 100 -- amount of pixels finger must travel to initiate page swipe local tweenTime = 500 local animStep = 1 local readyToContinue = false -- function to show next animation -- -- -- local function scrollListener( event ) local phase = event.phase if ( phase == "began" ) then print( "Scroll view was touched" ) elseif ( phase == "moved" ) then print( "Scroll view was moved" ) elseif ( phase == "ended" ) then print( "Scroll view was released" ) end -- In the event a scroll limit is reached... if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached bottom limit" ) elseif ( event.direction == "down" ) then print( "Reached top limit" ) elseif ( event.direction == "left" ) then print( "Reached right limit" ) elseif ( event.direction == "right" ) then print( "Reached left limit" ) end end return true end local function backButtonRelease( self, event ) -- body if event.phase == "ended" or event.phase == "cancelled" then composer.gotoScene("layout", "slideRight", 800) return true end end local function homeButtonRelease( self, event ) -- body if event.phase == "ended" or event.phase == "cancelled" then composer.gotoScene("menu", "slideDown", 800) return true end end local backButton = widget.newButton { left = -2, top = -4, width = 150, height = 100, defaultFile = "buttonBack.png", --overFile = "buttonArrowOver.png", --label = "Layout", onRelease = backButtonRelease, --fontSize = 70, } local homeButton = widget.newButton { left = 630, top = -5, width = 150, height = 100, defaultFile = "buttonHome.png", --overFile = "buttonArrowOver.png", --label = "Layout", onRelease = backButtonRelease, --fontSize = 70, } local orchidAButton = widget.newButton { left = 55, top = 190, width = 650, height = 290, defaultFile = "orchidBtn.png", --overFile = "buttonArrowOver.png", --label = "Layout", --onRelease = backButtonRelease, --fontSize = 70, } local orchidAButton1 = widget.newButton { left = 55, top = 350, width = 650, height = 290, defaultFile = "orchidBtn.png", --overFile = "buttonArrowOver.png", --label = "Layout", --onRelease = backButtonRelease, --fontSize = 70, } local orchidAButton2 = widget.newButton { left = 55, top = 510, width = 650, height = 290, defaultFile = "orchidBtn.png", --onRelease = backButtonRelease, } local orchidAButton3 = widget.newButton { left = 55, top = 670, width = 650, height = 290, defaultFile = "orchidBtn.png", --onRelease = backButtonRelease, } local orchidAButton4 = widget.newButton { left = 55, top = 830, width = 650, height = 290, defaultFile = "orchidBtn.png", --onRelease = backButtonRelease, } function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist. -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc. local scrollView = widget.newScrollView { top = 0, left = 0, width = display.contentWidth, height = display.contentHeight, bottomPadding = 50, horizontalScrollDisabled = true, verticalScrollDisabled = false, --hideBackground = false, --scrollWidth = 600, --scrollHeight = 800, listener = scrollListener } -- create background image background = display.newImageRect( sceneGroup, "cool\_house\_bg.png", display.contentWidth, display.contentHeight ) background.anchorX = 0 background.anchorY = 0 background.x, background.y = 0, 0 --background.alpha = 0.5 scrollView:insert( background ) scrollView:insert( backButton ) scrollView:insert( homeButton ) scrollView:insert( orchidAButton ) scrollView:insert( orchidAButton1 ) scrollView:insert( orchidAButton2 ) scrollView:insert( orchidAButton3 ) scrollView:insert( orchidAButton4 ) -- create overlay --local overlay = display.newImageRect( sceneGroup, "pagebg2.png", display.contentWidth, display.contentHeight ) --overlay.anchorX = 0 --overlay.anchorY = 0 --overlay.x, overlay.y = 0, 0 sceneGroup:insert( scrollView ) sceneGroup:insert( background ) sceneGroup:insert( backButton ) sceneGroup:insert( homeButton ) sceneGroup:insert( orchidAButton ) sceneGroup:insert( orchidAButton1 ) sceneGroup:insert( orchidAButton2 ) sceneGroup:insert( orchidAButton3 ) sceneGroup:insert( orchidAButton4 ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. backButton.touch = backButtonRelease backButton:addEventListener( "touch", backButton ) homeButton.touch = homeButtonRelease homeButton:addEventListener( "touch", homeButton ) end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) -- remove event listener from background backButton:removeEventListener( "touch", backButton ) homeButton:removeEventListener( "touch", homeButton ) elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene
Really hope somebody can help me with this. Thank you.
Khairul.