0

I am creating a main menu and I want to handle my scenes with storyboard.

Here is my main.lua:

-- 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")

and here is my 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

But when I click/touch the text and/or the logo it doesn't transit to mainmenuscene.lua Any idea why?

4

2 回答 2

1

好吧,显然我忘了在 enterScene 方法中将事件监听器添加到徽标和文本中。另外,我打错了“gotoScene”,而是写了“goToScene”。

问题已解决。

于 2013-07-21T14:28:22.243 回答
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

于 2015-03-18T23:01:33.233 回答