Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Scene Manager question — Gideros Forum

Scene Manager question

I'm trying to learn how to use the SceneManager, so I made this:

main.lua:
sceneManager = SceneManager.new({
 
	["menu"] = Menu,
 
})
 
stage:addChild(sceneManager)
sceneManager:changeScene("menu")
menu.lua:
Menu = Core.class(Sprite)
 
function Menu:init()
	local botao = Bitmap.new(Texture.new("button.jpg"))
	stage:addChild(botao)
end
The button itself doesn't matter. I just putted something on the screen to try the scene management.
The real problem is this:
Uploading finished.
main.lua:1: attempt to index nil with 'new'
stack traceback:
	main.lua:1: in function
Am I doing this right? The tutorial i'm following is 5 years old, so if i'm doing something wrong please tell me!
Thanks in advance!!!

Comments

  • MoKaLuxMoKaLux Member
    edited April 2023 Accepted Answer
    Since it is a plugin I think you need to initialize it:
    require "scenemanager"
    Other than that, your code looks good.

    Let me share how I do it :)

    init.lua:
    -- plugins
    require "scenemanager"
    require "easing"
    -- globals
    screenwidth, screenheight = application:get("screenSize") -- the actual user's screen size, yes!
    myappleft, myapptop, myappright, myappbot = application:getLogicalBounds()
    myappwidth, myappheight = myappright - myappleft, myappbot - myapptop
    ...
    main.lua:
    -- scene manager
    scenemanager = SceneManager.new(
    	{
    		["menu"] = Menu,
    		["levelX"] = LevelX, -- maker
    		["levelY"] = LevelY, -- viewer
    	}
    )
    stage:addChild(scenemanager)
    scenemanager:changeScene("menu")
    -- tables
    transitions = {
    	SceneManager.moveFromRight, -- 1
    	SceneManager.moveFromLeft, -- 2
    	SceneManager.moveFromBottom, -- 3
    	SceneManager.moveFromTop, -- 4
    	SceneManager.moveFromRightWithFade, -- 5
    	SceneManager.moveFromLeftWithFade, -- 6
    	SceneManager.moveFromBottomWithFade, -- 7
    	SceneManager.moveFromTopWithFade, -- 8
    	SceneManager.overFromRight, -- 9
    	SceneManager.overFromLeft, -- 10
    	SceneManager.overFromBottom, -- 11
    	SceneManager.overFromTop, -- 12
    	SceneManager.overFromRightWithFade, -- 13
    	SceneManager.overFromLeftWithFade, -- 14
    	SceneManager.overFromBottomWithFade, -- 15
    	SceneManager.overFromTopWithFade, -- 16
    	SceneManager.fade, -- 17
    	SceneManager.crossFade, -- 18
    	SceneManager.flip, -- 19
    	SceneManager.flipWithFade, -- 20
    	SceneManager.flipWithShade, -- 21
    }
    easings = {
    	easing.inBack, -- 1
    	easing.outBack, -- 2
    	easing.inOutBack, -- 3
    	easing.inBounce, -- 4
    	easing.outBounce, -- 5
    	easing.inOutBounce, -- 6
    	easing.inCircular, -- 7
    	easing.outCircular, -- 8
    	easing.inOutCircular, -- 9
    	easing.inCubic, -- 10
    	easing.outCubic, -- 11
    	easing.inOutCubic, -- 12
    	easing.inElastic, -- 13
    	easing.outElastic, -- 14
    	easing.inOutElastic, -- 15
    	easing.inExponential, -- 16
    	easing.outExponential, -- 17
    	easing.inOutExponential, -- 18
    	easing.linear, -- 19
    	easing.inQuadratic, -- 20
    	easing.outQuadratic, -- 21
    	easing.inOutQuadratic, -- 22
    	easing.inQuartic, -- 23
    	easing.outQuartic, -- 24
    	easing.inOutQuartic, -- 25
    	easing.inQuintic, -- 26
    	easing.outQuintic, -- 27
    	easing.inOutQuintic, -- 28
    	easing.inSine, -- 29
    	easing.outSine, -- 30
    	easing.inOutSine, -- 31
    }
    menu.lua:
    Menu = Core.class(Sprite)
     
    function Menu:init()
    	-- BG
    	application:setBackgroundColor(0x227178)
    	-- btns
    	-- btnMaker = Button.new(...)
    	-- btns listeners
    	btnMaker:addEventListener("clicked", function() self:gotoScene("levelX") end)
    	-- LISTENERS
    	self:addEventListener("enterBegin", self.onTransitionInBegin, self)
    	self:addEventListener("enterEnd", self.onTransitionInEnd, self)
    	self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
    	self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
    end
     
    -- GAME LOOP
    function Menu:onEnterFrame(e)
    end
     
    -- EVENT LISTENERS
    function Menu:onTransitionInBegin() end
    function Menu:onTransitionInEnd()
    	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function Menu:onTransitionOutBegin()
    	self:removeAllListeners()
    end
    function Menu:onTransitionOutEnd() end
     
    -- change scene
    function Menu:gotoScene(xscene)
    	scenemanager:changeScene(
    		xscene, 1,
    		transitions[math.random(1, #transitions)],
    		easings[math.random(1, #easings)]
    	)
    end
    Hope this helps
    https://wiki.gideros.rocks/index.php/SceneManager
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • Thank you veeeery much @MoKaLux !!!
    You're making it true for me that Gideros Mobile community is the best!

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited April 2023
    Here is a project that uses scenemanager, you may have a look? (just download the zip and open the gideros project):
    https://github.com/mokalux/GIDEROS_PLATFORMER_CBUMP_GCAM_TECS
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited April 2023
    EDIT: I tested your code and it works fine but you need:
    - add scenemanager to gideros plugins (right click Plugins) -> add plugin


    - require "scenemanager"

    ;)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • edited April 2023
    Talking about your repository, I just tried now, but seems like there's something wrong. The menu scene appears with just a blue screen. But it's useful anyway. Thank you for sharing!

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • the blue screen is maybe this application:setBackgroundColor(0x227178) :)

    PS: don't add your button to the stage but add it to your scene (here the menu scene represented by self)
    function Menu:init()
    	local botao = Bitmap.new(Texture.new("button.jpg"))
    --	stage:addChild(botao) -- not so good
    	self:addChild(botao) -- prefered way, self is your menu sprite defined in Menu = Core.class(Sprite)
    end
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited April 2023

    Talking about your repository, I just tried now, but seems like there's something wrong. The menu scene appears with just a blue screen. But it's useful anyway. Thank you for sharing!

    Ah I see, in the repository the menu scene is empty, just blue background, I was focusing on cbump plugin example. All happen in the LevelX scene :)

    This example is more complete :p https://github.com/mokalux/PLATFORMER_CBUMP_TECS_20221101_wodt
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.