我正在创建一个主菜单,我想用故事板处理我的场景。
这是我的主要内容:
-- Hide status bar
display.setStatusBar(display.HiddenStatusBar);
-- Some global variables
local assetsPath = "media/"
local lettersPath = "media/letters/"
-- Initialize storyboard
local storyboard = require ("storyboard")
local widget = require("widget")
-- Load first scene
storyboard.gotoScene("splashscene")
这是我的splashscene.lua:
local storyboard = require("storyboard") local scene = storyboard.newScene()local bgimg, moratechlogo,text
local function onSceneTouch(self,event)
if event.phase == "began" then storyboard.goToScene("mainmenuscene", "fade", 400) return true end
end
function scene:createScene(event)
local screenGroup = self.view bgimg = display.newImage("media/splashBG.png",0,0) moratechlogo = display.newImage("media/moratechgames.png", display.contentWidth/2 - 150, display.contentHeight/2 - 100) screenGroup:insert(bgimg) screenGroup:insert(moratechlogo) moratechlogo.touch = onSceneTouch text = display.newText("Tap here to continue...", display.contentWidth /2 - 76, display.contentHeight - 30) text:setTextColor(255) screenGroup:insert(text) text.touch = onSceneTouch
end
function scene:enterScene( event ) local screenGroup = self.view
end
function scene:exitScene( event )
-- remove touch listener for image text:removeEventListener( "touch", text ) moratechlogo:removeEventListener("touch",moratechlogo) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
但是当我点击/触摸文字和/或徽标时,它不会转移到mainmenuscene.lua 知道为什么吗?
答案 0 :(得分:1)
好的,显然我忘了将事件监听器添加到enterScene方法中的徽标和文本中。 另外,我输错了“gotoScene”,我写了“goToScene”。
问题已解决。
答案 1 :(得分:0)
您也可以尝试使用widget.newButton
http://docs.coronalabs.com/api/library/widget/newButton.html
该按钮具有标签,背景图片等选项!
local widget = require( "widget" )
local button1 = widget.newButton {
left = 100,
top = 200,
id = "button1",
label = "Default",
onPress = function()
storyboard.gotoScene( "scenes", {effect="someEffect", time=someTime )
}
如果您创建了其他任何功能,例如storyboard.hide_someObject()
,您可以将其放在storyboard.gotoScene
下方,当您按下按钮时会发生onPress