Hi guys i dont understand how to switch scene. Every time i press the button that makes me go to another menu the previous menu doesn’t disappear, well just some buttons. And if i want to go back to the previous menu it wont let me. Im a little bit confused :huh:
All objects must be inserted into sceneGroup (scene.view) in order for Composer to remove them automatically.
Hi,
Take a look at the “Important” section here: https://docs.coronalabs.com/guide/system/composer/index.html#aboutscenes
-dev
like this ?
[lua] local sceneGroup = self.view
local backgroundImage = …
sceneGroup:insert(backgroundImage)[/lua] if it is it gives me an error
Please be more specific. ‘An error’ doesn’t mean anything, there are hundreds of possible errors and thousands of possible causes.
In the future, should download these two entire repositories:
- (OLD) Hangouts Content (includes multiple full games): https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts
- My RG Freestuff Repository with years and years of forums answers (code): https://github.com/roaminggamer/RG_FreeStuff
For now… just download this:
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip
Unzip it… then run the example in folder ‘5_frame’. Once you have run it, go look at the file ‘5_frame/ifc/mainMenu.lua’
Pay close attention to how I deal with new display objects and how I place them in the scene group.
The scene group manages these items, which is the problem you’re running into (as others pointed out above).
Just for giggles, I’m pasting some code from the mainMenu.lua file here:
function scene:create( event ) local sceneGroup = self.view -- Create a simple background local back = display.newImageRect( sceneGroup, "images/protoBack.png", 380\*2, 570\*2 ) back.x = centerX back.y = centerY if(w\>h) then back.rotation = 90 end -- Create a label showing which scene this is local label = display.newEmbossedText( sceneGroup, "Main Menu", centerX, 40, native.systemFont, 60 ) label:setFillColor( 0xCC/255, 1, 1 ) local color = { highlight = { r=1, g=1, b=1 }, shadow = { r=0, g=1, b=0.3 } } label:setEmbossColor( color ) -- Create some buttons for navigation local playButton = PushButton( sceneGroup, centerX, centerY, "Play", onPlay, { labelColor = {0,1,0}, labelSize = 24 } ) local optionsButton = PushButton( sceneGroup, centerX, centerY + 100, "Options", onOptions, { labelColor = {0,1,1}, labelSize = 24 } ) end
sorry but i still don’t get how you hide objects when switching scenes
You don’t, Composer does, if you follow the instructions correctly.
i don’t know im still confused
cant i just add all my objects into a group and do [lua] objGrp.isVisible = false [/lua] when switching scenes to hide the objects i don’t need?
You can but this is just papering over another problem. Composer just works if you follow the API docs, in ten years making 50+ games I’ve never had an issue.
When something doesn’t work in my projects and I lose sight of why, I rip out the code and start again, checking each and every line does what it should do before moving on.
so i did this [lua] local objGrp=display.newGroup()
local cleanObj=function()
objGrp:removeSelf()
objGrp=nil
end [/lua]
and added every object in this group like this
[lua] local button1 = widget.newButton
{
left = 35 ,
top = 400 ,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/1.png”),
overFile = (“Sfondi/icons/1.png”),
onEvent = handleButtonEvent1
}
objGrp:insert(button1) [/lua] the number disappears when i click on the other menu but when i get back to the first one it does not appear back …
Are you calling cleanObj when you leave the scene?
Composer has a few modes but by default, it will remove objects from the screen that are inserted into .view, but keep them in memory for when you return to the same scene. Therefore it does not ‘redraw’ everything so if you remove them yourself then nothing will appear. But without seeing all the code in context I’m just guessing what you’re doing.
can i send you my code in pvt ?
Sure, no problem.
sent u a message, thank you
I giggled.
-dev