Hello,
I was just trying to make a simple intro for my game. A background that switches from image and then the app goes to the menu.
I got it working with 2 different scripts for both backgrounds. But I am trying to get the intro it into 1 script.
Somehow it never goes to the menu at this line: storyboard.gotoScene( “menu”, 500 )
But it is still running the print commands i put around it!
And the same line of code works if I use only one background.
Anybody knows what the problem is I can not get it figured out.
Here is my code for the Intro:
-----------------------------------------------------------------------------------------
--
-- menu.lua
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local background
-- include Background class
require "Background"
--------------------------------------------
-- 'onRelease' event listener for playBtn
local function onTimerExpires()
-- Change background Image
background = Background:changeImage("Graphics/Intros/introRaB.jpg")
--startTimer2()
return true -- indicates successful timer expire
end
local function onTimerExpires2()
print("lol")
-- go to intro2.lua scene
storyboard.gotoScene( "menu", 500 )
print("went to menu")
return true -- indicates successful timer expire
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
background = Background:new(0,0,display.TopLeftReferencePoint,"Graphics/Intros/introLogo.jpg")
-- all display objects must be inserted into group
group:insert( background )
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.)
startTimer()
startTimer2()
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.)
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
end
function startTimer()
timer.performWithDelay(5000, onTimerExpires)
end
function startTimer2()
timer.performWithDelay(10000, onTimerExpires2)
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
My code for the Background:
[code]
Background = {}
local background
function Background:new(startX, startY, refPoint, imageSource)
background = display.newImage( imageSource )
background:setReferencePoint(refPoint)
background.x = startX
background.y = startY
return background
end
function Background:changeImage(imageSource)
background = display.newImage( imageSource )
end
return Background
[/code] [import]uid: 118839 topic_id: 24399 reply_id: 324399[/import]
[import]uid: 118839 topic_id: 24399 reply_id: 99380[/import]