Reputation: 1058
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?
Upvotes: 0
Views: 730
Reputation: 339
You could also try using widget.newButton
http://docs.coronalabs.com/api/library/widget/newButton.html
The button has options for a label, background image and more!
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 )
}
If you created any other functions like storyboard.hide_someObject()
you can put it right below storyboard.gotoScene
and it will happen onPress
when you press the button
Upvotes: 0
Reputation: 1058
Okay so apparently I forgot to add the eventlisteners to the logo and text in the enterScene method. Also, I mistyped "gotoScene", i wrote "goToScene" instead.
Problem fixed.
Upvotes: 1