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
Let me share how I do it
init.lua:
https://wiki.gideros.rocks/index.php/SceneManager
Likes: Gabriel_Mercês
You're making it true for me that Gideros Mobile community is the best!
Likes: MoKaLux
https://github.com/mokalux/GIDEROS_PLATFORMER_CBUMP_GCAM_TECS
Likes: Gabriel_Mercês
- add scenemanager to gideros plugins (right click Plugins) -> add plugin
- require "scenemanager"
Likes: Gabriel_Mercês
Likes: MoKaLux
PS: don't add your button to the stage but add it to your scene (here the menu scene represented by self)
Likes: Gabriel_Mercês
This example is more complete https://github.com/mokalux/PLATFORMER_CBUMP_TECS_20221101_wodt
I have read to prevent memory leaks you should initialise all your stuff in onTransitionInEnd, I tried this and other stuff but still some memory leaks happen.
Now I want to move away from scenemanager but I have some doubts
Is this how you would do a scene transition?
Thank you for your insights
I guess so, then you can say Menu = nil and collectgarbage() or wait for the next auto collection.. unless you need to keep it alive for some reason. Why do you want to keep it existing in the background?
You could also add Menu directly to your Scene instead of adding it to stage.
AFAIK what might cause leaks is something that keeps being created (initialized) and never removed. If you manage to add stuff as local or as a property of the scene itself it should be removed as soon as the scene itself is removed.
There is also another thing that might happen: if you collectgarbage during a transition between two scenes, it might not be guaranteed that the first scene is already "dead" when you call the collector - therefore it cannot remove (yet) the stuff loaded in the first scene. I am not sure to remember when that occurred to me: I think I was reloading the same scene with different parameters (like from level1 to level2)
When I had this issue I just added an almost empty "passage scene/loading screen" whose only reason to be was to allow cleaning up the stuff in the previous scene before loading the new one.
Likes: MoKaLux