Looking to learn about how to change scenes. I had a good look through the reference and documents but couldn't find how to do it. Any starting points would be much appreciated.
main.lua is uploading. Uploading finished. scenemanager.lua:264: attempt to index field '?' (a nil value) stack traceback: scenemanager.lua:264: in function 'changeScene' main.lua:15: in main chunk
@Tom2012 sometimes you may want for objects to appear on screen only after the transition is ended. Or for example add touch or mouse listeners only when transition is ended, so you won't allow dragging something on the screen while in transition, which might provide some unexpected dragging results
Comments
http://www.giderosmobile.com/blog/2011/11/17/gideros-scene-manager/
http://appcodingeasy.com/Gideros-Mobile/Manage-Scenes-in-Gideros-Mobile
1) Copy scenemanager.lua to project folder
2) Add this code to main.lua, defining scenes
--define scenes
sceneManager = SceneManager.new({
--start scene
["start"] = start,
--pack select scene
["pack_select"] = pack_select,
--level select scene
["level_select"] = level_select,
--level itself
["level"] = level
})
--add manager to stage
stage:addChild(sceneManager)
3) On each scene1.lua type file... add:
level_select = gideros.class(Sprite)
function level_select:init()
-- The scenes code goes here
end
Thanks!
Here's what I have in my main.lua
--define scenes
sceneManager = SceneManager.new({
--start scene
["scene 1"] = start,
--pack select scene
["scene 2"] = pack_select,
})
--add manager to stage
stage:addChild(sceneManager);
-- Jump to first scene
sceneManager:changeScene("start", 1, SceneManager.flipWithFade, easing.outBack);
I get:
stack traceback:
scenemanager.lua:264: in function 'changeScene'
main.lua:12: in main chunk
Thanks
Tom
--define scenes
local sceneManager = SceneManager.new({
--start scene
["scene 1"] = scene1,
--pack select scene
["scene 2"] = pack_select
})
local scenes = {"scene 1" , "pack_select" }
--add manager to stage
stage:addChild(sceneManager);
sceneManager:changeScene("scene 1", 1, SceneManager.flipWithFade, easing.outBack);
main.lua is uploading.
Uploading finished.
scenemanager.lua:264: attempt to index field '?' (a nil value)
stack traceback:
scenemanager.lua:264: in function 'changeScene'
main.lua:15: in main chunk
The top of each scene lua file needs to have the key
scene1 = gideros.class(Sprite)
function scene1:init()
I'd had nightmares in the past getting a competing product's scene manager to work!
I would use scene1 = Core.class(Sprite)
as gideros.class is deprecated
cheers
evs
(Search 5.7.3 for some code that shows an example scene (“MyScene”) and how you might use the “enterEnd” and “exitBegin” events).
Going to look into that now.
What would be the advantage of using those events as opposed to putting variables, listeners and logic in the scene's function here:
scene1 = Core.class(Sprite)
function scene1:init()
-- here
end
sometimes you may want for objects to appear on screen only after the transition is ended.
Or for example add touch or mouse listeners only when transition is ended, so you won't allow dragging something on the screen while in transition, which might provide some unexpected dragging results
At the moment I have a scene : Menu.lua
In that I have this function:
function startGame()
print("start game");
sceneManager:changeScene("Level 1", 1, SceneManager.flipWithFade, easing.outBack);
end
playButton:addEventListener("click", startGame);
When the button is clicked it says 'start game' but does not change scene.
Any idea why?
Thanks
Tom
In my scenes I was using stage:addChild where it should be self:addChild