我有这种奇怪的情况。我有2个场景。我可以在模拟器中从 1 转到另一个,但是当我在设备上执行相同操作时它会崩溃......
这是第一个场景(菜单)的代码
菜单.lua
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona s "widget" library
local widget = require ("widget")
-- forward declarations and other locals
local playBtn
local optsBtn
local helpBtn
-- Levels Menu
local function onPlayBtnRelease()
-- ads.hide()
storyboard.gotoScene( "levels", "fade", 500 )
return true -- indicates successful touch
end
-- Options
local function onOptionsBtnRelease()
storyboard.gotoScene( "options", "fade", 500 )
return true -- indicates successful touch
end
-- Help
local function onHelpBtnRelease()
storyboard.gotoScene( "help", "fade", 500 )
return true -- indicates successful touch
end
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene s view does not exist:
function scene:createScene( event )
local group = self.view
-- display a background image
local background = display.newImageRect( "background.jpg", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
-- create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( "title.png", 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = display.contentHeight / 5
-- create a widget button (which will loads levels.lua on release)
playBtn = widget.newButton{
label="Play Now",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onPlayBtnRelease -- event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight * 2 / 5
-- button for options (options.lua)
optsBtn = widget.newButton{
label="Options",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onOptionsBtnRelease -- event listener function
}
optsBtn:setReferencePoint( display.CenterReferencePoint )
optsBtn.x = display.contentWidth*0.5
optsBtn.y = display.contentHeight * 3 / 5
-- button for options (help.lua)
helpBtn = widget.newButton{
label="Help",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onHelpBtnRelease -- event listener function
}
helpBtn:setReferencePoint( display.CenterReferencePoint )
helpBtn.x = display.contentWidth*0.5
helpBtn.y = display.contentHeight * 4 / 5
-- Load Configurations
local utili = require( "utility" )
mySettings = utili.loadTable("BlastsOptions.json")
-- all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
group:insert( optsBtn )
group:insert( helpBtn )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-- Audio ***
local menusound = audio.loadStream("sounds/menusback.mp3")
if mySettings.musicOn == true then
audio.play (menusound, {loop=-1})
end
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
audio.stop()
end
-- If scene s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
--if playBtn then
-- playBtn:removeSelf() -- widgets must be manually removed
-- playBtn = nil
--end
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene s view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene s transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
这是第二个的代码:
你能帮我找出可能是什么问题吗?
关卡.lua
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona s "widget" library
local widget = require ("widget")
--------------------------------------------
local function onKeyEvent( event )
if (event.keyName == "back") and (system.getInfo("platformName") == "Android") then
storyboard.gotoScene( "menu", "fade", 500 )
return true
end
return false
end
Runtime:addEventListener( "key", onKeyEvent );
-- forward declarations and other locals
local play1Btn
local play2Btn
local menuBtn
-- 'onRelease' event listener for playBtn
local function onLeve1BtnRelease()
-- go to level1.lua scene
audio.stop ()
storyboard.gotoScene( "level1", "fade", 500 )
return true -- indicates successful touch
end
local function onLeve2BtnRelease()
-- go to level1.lua scene
-- ads.hide()
storyboard.gotoScene( "level1", "fade", 500 )
return true -- indicates successful touch
end
local function onMenuBtnRelease()
-- go to level1.lua scene
storyboard.gotoScene( "menu", "fade", 500 )
return true -- indicates successful touch
end
-- Called when the scene s view does not exist:
function scene:createScene( event )
local group = self.view
-- display a background image
local background = display.newImageRect( "background.jpg", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
-- create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( "select-Level.png", 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = display.contentHeight / 5
-- create a widget button (which will loads level1.lua on release)
play1Btn = widget.newButton{
label="Level 1",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onLeve1BtnRelease -- event listener function
}
play1Btn:setReferencePoint( display.CenterReferencePoint )
play1Btn.x = display.contentWidth*0.5
play1Btn.y = display.contentHeight * 2 / 5
-- button for options (options.lua)
play2Btn = widget.newButton{
label="Level 2",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onLeve2BtnRelease -- event listener function
}
play2Btn:setReferencePoint( display.CenterReferencePoint )
play2Btn.x = display.contentWidth*0.5
play2Btn.y = display.contentHeight * 3 / 5
-- button for options (help.lua)
menuBtn = widget.newButton{
label="Return",
labelColor = { default={255}, over={128} },
defaultFile="button.png",
overFile="button-over.png",
width=154, height=40,
onRelease = onMenuBtnRelease -- event listener function
}
menuBtn:setReferencePoint( display.CenterReferencePoint )
menuBtn.x = display.contentWidth*0.5
menuBtn.y = display.contentHeight * 4 / 5
-- all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( play1Btn )
group:insert( play2Btn )
group:insert( menuBtn )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
end
-- If scene s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene s view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene s transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
非常非常感谢。我是 Corona 的新手,我一直坚持这个:(