0

我有一个计时器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
4

1 回答 1

0

我不完全确定您的问题是什么,但我认为我有一个好主意,我也是 Corona 的新手并且遇到了类似的问题。

处理场景时,您需要清除destroyScene函数上的重要变量。基本上,如果您不这样做并回到同一个场景,您可能会遇到奇怪的问题。您还可以做另一件事。

一旦你进入你的下一个场景,你可以removeScene从记忆中的前一个场景(这将清除所有它)。您可以在下一个场景的 enterScene 函数中执行此操作。我实现了一个解决方案,无论之前的场景是什么(所以它更加动态)。

当我调用下一个场景时,我会这样做:

local options = {effect = "fade",800,params={destroy = true,toDestroy = 'scenes.gameOver'}}
storyboard.gotoScene('scenes.mainMenu',options)

然后在我的下一个场景中,enterScene我检查参数,如果它在那里,那么我删除场景:

local params = event.params
--Check for any previous scenes to destroy
if params and params.destroy == true then
    storyboard.removeScene(params.toDestroy)
end 

这可能符合您的需要。

于 2013-11-05T21:14:02.033 回答