HELLO! I am a newbie and trying to make a game with the help of some templates tutorial.
I need help in restricting touch event during pause. I manage to pause time but i can still touch objects and flips it.
Hope someone could help me.
Thanks a bunch!
local storyboard = require "storyboard" local scene = storyboard.newScene ( ) local widget = require( "widget" ) \_touchval = false display.setStatusBar(display.HiddenStatusBar); --Time's Up function timesupScene() local options = {effect = "fade",800,params={destroy = true,toDestroy = 'play'}} storyboard.gotoScene('timeend',options) end --Timer local tmr = 60 local timetext = display.newText("Time: " ,180,10,"Arial",20) timetext:setTextColor(255,0,0) local timeleft = display.newText(tmr,250,10,"Impact",21) timeleft:setTextColor(255,0,0) local myTimer function pauseGame() timer.pause(myTimer) \_paused.isVisible = false \_resume.isVisible = true Runtime:removeEventListener("touch") \_touchval = true end function resumeGame() timer.resume(myTimer) \_resume.isVisible = false \_paused.isVisible = true end local function closeScene(event) local options = {effect = "fade",800,params={destroy = true,toDestroy = 'play'}} storyboard.gotoScene('menu',options) end function tmeup() \_banner.isVisible = true \_timesup.isVisible = true \_closebuttonsmall.isVisible = true end --BG local bg = display.newImage("brownbg.png"); bg:toBack() function scene:createScene(event) \_banner = display.newImage("brown.png") \_banner.y = 250 \_timesup = display.newImage("timeisuptext.png") \_timesup.y = \_H/2 \_timesup.x =165 \_closebuttonsmall = display.newImage("closebuttonsmall.png") \_closebuttonsmall.y = 390 \_closebuttonsmall.x =280 \_closebuttonsmall:addEventListener ( "touch", closeScene ) \_banner.isVisible = false \_timesup.isVisible = false \_closebuttonsmall.isVisible = false end scene:addEventListener ( "createScene", scene ) --variable for score score = 0 --totalButtons variable to track number of buttons on screen totalButtons = 0 --variable to track button select secondSelect = 0 checkForMatch = false --button, buttonCover, and buttonImages table button = {} buttonCover = {} buttonImages = {1,1,6,6,7,7,8,8,9,9,10,10} --prime a last button selected variable lastButton = display.newImage("1.png"); lastButton.myName = 1; lastButton:toBack() --Score Word txtscore = display.newText( "Score: ", 20, 440, "Arial", 30 ) txtscore:setTextColor( 0,0,0) --match is found or not matchText = display.newText(" ", 0, 0, native.systemFont, 26) matchText:setReferencePoint(display.CenterReferencePoint) matchText:setTextColor(139,90,0) matchText.x = \_W/2 matchText.y = 50 --button grid x = -30 function scene:enterScene(event) local params = event.params --Check for any previous scenes to destroy if params and params.destroy == true then storyboard.removeScene(params.toDestroy) end tmr = 60 timeleft.text = 60 local function countTimer() tmr = tmr - 1 timeleft.text = tmr if tmr == 0 then tmeup() end end myTimer= timer.performWithDelay(1000,countTimer,60) timeleft.isVisible=true timetext.isVisible=true \_resume = display.newImage( "playbuttonsmall.png") \_resume.isVisible = false \_resume:addEventListener ( "touch", resumeGame ) \_resume.x = 73 \_resume.y =30 \_paused = display.newImage( "pausebuttonsmall.png") \_paused:addEventListener ( "touch", pauseGame ) \_paused.x = 27 \_paused.y=30 --Group declaration local group = self.view function game(object, event) if(event.phase == "began") then if(checkForMatch == false and secondSelect == 0) then --Flip over first button buttonCover[object.number].isVisible = false; lastButton = object checkForMatch = true elseif(checkForMatch == true) then if(secondSelect == 0 and lastButton ~= object) then --Flip over second button buttonCover[object.number].isVisible = false; secondSelect = 1; --If buttons do not match, flip buttons over if(lastButton.myName ~= object.myName) then matchText.text = "Match Not Found!"; timer.performWithDelay(1250, function() matchText.text = " "; checkForMatch = false; secondSelect = 0; buttonCover[lastButton.number].isVisible = true; buttonCover[object.number].isVisible = true; end, 1) --If buttons DO match, remove buttons elseif(lastButton.myName == object.myName) then matchText.text = "Match Found!"; score = score + 5 txtscore.text = "Score: " .. score timer.performWithDelay(1250, function() matchText.text = " "; checkForMatch = false; secondSelect = 0; lastButton:removeSelf(); object:removeSelf(); buttonCover[lastButton.number]:removeSelf(); buttonCover[object.number]:removeSelf(); if score == 30 then nexteasyScene() end end, 1) end end end end end --Place buttons on screen for count = 1,4 do x = x + 75 y = 20 for insideCount = 1,3 do y = y + 90 --Assign each image a random location on grid temp = math.random(1,#buttonImages) button[count] = display.newImage(buttonImages[temp] .. ".png"); --Position the button button[count].x = x; button[count].y = y; --Give each a button a name button[count].myName = buttonImages[temp] button[count].number = totalButtons --Remove button from buttonImages table table.remove(buttonImages, temp) --Set a cover to hide the button image buttonCover[totalButtons] = display.newImage("button.png"); buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y; totalButtons = totalButtons + 1 --HERE IS WHERE THE EVENT LISTENER IS PUT IN EACH BUTTON button[count].touch = game button[count]:addEventListener( "touch", button[count] ) end end end scene:addEventListener ( "enterScene", scene ) function scene:exitScene(event) score = 0 timer.pause(myTimer) timeleft.isVisible=false timetext.isVisible=false \_resume.isVisible=false \_paused.isVisible=false matchText.isVisible = false txtscore.isVisible = false score = 0 totalButtons = 0 secondSelect = 0 checkForMatch = false lastButton.myName = 1; \_banner.isVisible = false \_timesup.isVisible = false \_closebuttonsmall.isVisible = false end scene:addEventListener ( "exitScene", scene ) function scene:destroyScene(event) end scene:addEventListener ( "destroyScene", scene ) return scene