我有一个计时器play.lua
,当它达到 0 时,它会自动转到timeend.lua
这表明它的时间到了。但是当我关闭(通过按钮)的场景时,timeend
它会进入menu.lua
但不能正常工作。当我触摸菜单中的播放按钮时,它只显示背景。
菜单.lua
local storyboard = require "storyboard"
local scene = storyboard.newScene ( )
local widget = require( "widget" )
local _X, _Y = display.contentWidth/2, display.contentHeight/2
local function playScene(event)
storyboard.gotoScene("easymediumhard", "fade", 100)
helpbutton.isVisible = false
playbutton.isVisible = false
end
local function helpScene(event)
storyboard.gotoScene("help", "fade", 100)
helpbutton.isVisible = false
playbutton.isVisible = false
end
function scene:createScene(event)
end
scene:addEventListener ( "createScene", scene )
function scene:enterScene(event)
local group = self.view
--BG
local bg = display.newImage("brownbg.png");
group:insert(bg)
--Logo
local logo = display.newImage("logo.png")
logo.x = 200
logo.y = 70
group:insert(logo)
local brown = display.newImage("bannermenu.png")
brown.y = 350
group:insert(brown)
--Button
playbutton = widget.newButton
{
defaultFile = "playbutton.png",
overFile = "playbuttontouched.png",
onRelease = playScene,
}
playbutton.y = _Y+78
playbutton.x = _W/2
helpbutton = widget.newButton
{
defaultFile = "helpbutton.png",
overFile = "helpbuttontouched.png",
onRelease = helpScene,
}
helpbutton.y = _Y+140
helpbutton.x = _W/2
end
scene:addEventListener ("enterScene",scene)
function scene:exitScene(event)
end
scene:addEventListener ( "exitScene", scene )
function scene:destroyScene(event)
end
scene:addEventListener ( "destroyScene", scene )
return scene
易中硬.lua
local storyboard = require "storyboard"
local scene = storyboard.newScene ( )
local widget = require( "widget" )
local _X, _Y = display.contentWidth/2, display.contentHeight/2
local function easyScene(event)
storyboard.gotoScene("play", "fade", 1000)
end
function scene:createScene(event)
end
scene:addEventListener ( "createScene", scene )
function scene:enterScene(event)
local group = self.view
--BG
local bg = display.newImage("brownbg.png");
group:insert(bg)
local brown = display.newImage("bannermenu.png")
brown.y = 250
group:insert(brown)
--Easy Medium Hard text
local easy = display.newImage("easytext.png")
easy:addEventListener ( "touch", easyScene )
easy.x = _W/2
easy.y = 210
group:insert(easy)
local medium = display.newImage("mediumtext.png")
medium.x = _W/2
medium.y = 255
group:insert(medium)
local hard = display.newImage("hardtext.png")
hard.x = _W/2
hard.y = 298
group:insert(hard)
end
scene:addEventListener ("enterScene", scene)
function scene:destroyScene(event)
end
scene:addEventListener ( "destroyScene", scene )
return scene
玩.lua
local storyboard = require "storyboard"
local scene = storyboard.newScene ( )
--BG
local bg = display.newImage("brownbg.png");
--TIMES UP
local function timesupScene()
storyboard.gotoScene("timeend", "fade", 100)
end
--Timer
local tmr = 60
local timetext = display.newText("Time: " ,180,10,"Arial",20)
timetext:setTextColor(64,64,64)
local timeleft = display.newText(tmr,250,10,"Impact",21)
timeleft:setTextColor(64,64,64)
local myTimer
local function countTimer()
tmr = tmr - 1
timeleft.text = tmr
if tmr == 55 then
timesupScene()
end
end
myTimer= timer.performWithDelay(2000,countTimer,60)
local function pauseGame()
timer.pause(myTimer)
_paused.isVisible = false
_resume.isVisible = true
end
local function resumeGame()
timer.resume(myTimer)
_resume.isVisible = false
_paused.isVisible = true
end
_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
function scene:createScene(event)
end
scene:addEventListener ( "createScene", scene )
function scene:exitScene(event)
timer.cancel(myTimer)
tmr = 60
timetext:removeSelf();
_resume:removeSelf();
_paused:removeSelf();
end
scene:addEventListener ( "exitScene", scene )
function scene:destroyScene(event)
end
scene:addEventListener ( "destroyScene", scene )
return scene
时间结束.lua
local storyboard = require "storyboard"
local scene = storyboard.newScene ( )
local widget = require( "widget" )
local _W, _H = display.contentWidth/2, display.contentHeight/2
local function closeScene(event)
local previousScene = storyboard.getPrevious()
storyboard.gotoScene("easymediumhard")
return true
end
function scene:createScene(event)
_banner = display.newImage("bannermenu.png")
_banner.isVisible = false
_banner.y = 200
_timesup = display.newImage("timeisuptext.png")
_timesup.isVisible = false
_timesup.y = 210
_timesup.x =165
_closebuttonsmall = display.newImage("closebuttonsmall.png")
_closebuttonsmall.isVisible = false
_closebuttonsmall:addEventListener ( "touch", closeScene )
_closebuttonsmall.y = _H/2 +180
_closebuttonsmall.x =_W/2+210
end
scene:addEventListener ( "createScene", scene )
function scene:enterScene(event)
_banner.isVisible = true
_timesup.isVisible = true
_closebuttonsmall.isVisible = true
end
scene:addEventListener ("enterScene",scene)
function scene:exitScene(event)
_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