我已经使用coronaSDK编辑器在我的应用程序中有场景。我有一个选项按钮,可以进入选项场景。但是当我在选项场景上放一个按钮返回mainMenu场景时它不起作用
mainMenu.lua
local composer = require( "composer" )
local scene = composer.newScene()
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
local backgroundimg = display.newImage("image/mainBackground.png")
backgroundimg.x = display.contentWidth*0.5
backgroundimg.y = display.contentHeight*0.5
sceneGroup:insert( backgroundimg )
local function startListener( event )
composer.gotoScene( "scene.play" )
end
local start = display.newRect(65,99.5,161,161)
start.alpha = 0.01
start:addEventListener( "tap", startListener )
local function leaderListener( event )
composer.gotoScene( "scene.leaderboards" )
end
local leader = display.newRect(208,227.5,147,147)
leader.alpha = 0.01
leader:addEventListener( "tap", leaderListener )
local function optionsListener( event )
composer.gotoScene( "scene.options" )
end
local options = display.newRect(332,92.5,147,147)
options.alpha = 0.01
options:addEventListener( "tap", optionsListener )
local function quitListener( event )
os.exit()
end
local quit = display.newRect(432,240.5,120,120)
quit.alpha = 0.01
quit:addEventListener( "tap", quitListener )
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
elseif ( phase == "did" ) then
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
elseif ( phase == "did" ) then
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene
options.lua
local composer = require( "composer" )
local scene = composer.newScene()
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
local function startListener( event )
composer.gotoScene( "scene.mainMenu" )
end
local start = display.newRect(65,99.5,161,161)
start.alpha = 1
start:addEventListener( "tap", startListener )
end
答案 0 :(得分:1)
尝试使用:
composer.gotoScene( "mainMenu" )
此外,您不是要将对象添加到场景组。因此,当场景发生变化时,不会自动删除对象。