This absolutely not a stupid question at all! In-fact, this topic is constantly brought up, as there are many ways to tackle this approach.
The first approach I would explore is the storyboard API made by corona. This allows you to build your application with “scenes”. Each scene is represented by a separate file, for example main menu.lua, options.lua, game.lua. You can switch between scenes using multiple type of transitions. This API can be a bit overwhelming if you are a beginner, but there is a decent chunk of documentation available.
Another approach will be to use the director class. This is a 3rd party API built by a corona user (Ricardo Rauber) that works the same way the storyboard API work, by creating a separate file for each scene. I personally find director to be the easier of the two to understand. You can download director and look at information by visiting this link: http://rauberlabs.blogspot.com/2011/08/director-14-books.html
And here is also a nice little video tutorial going through some basics of how to use it:
http://www.youtube.com/watch?v=RAktnj7nwos
If you feel that these are too overwhelming, you can take the good old fashioned way of handling “scenes” with the display.newGroup() function.
Think of a group like a folder. I can create a group called “menu” and create all of my menu items and insert them into the group. Then do the same for my separate “scenes” or “pages” and insert them into their own group.
You were spot on with your post, because a group itself is a display object, so you can manipulate it like any other object and all of the items you have inserted into the group will react the same.
Here is a very light weight example:
local menu = display.newGroup()
local playbtn = display.newImage("playbtn.png")
playbtn.x = 160
playbtn.y = 240
menu:insert(playbtn)
local optionsbtn = display.newImage("optionsbtn.png")
optionsbtn.x = 160
optionsbtn.y = playbtn.y + 40
menu:insert(optionsbtn)
Now this is just the creation of a simple group, and then 2 objects that I created and inserted into the group. Now I can manipulate this group anyway I would like. For Example:
-- Use this
menu.alpha = 0
-- Or you can use this
menu.isVisible = false
Setting the menu group alpha attribute to 0 will make both the playbtn and optionsbtn also set to 0, thus resulting in an invisible menu. The same effect works with isVisible (alpha gives you the option to make your group transparent but still visible if you so choose, isVisible simply makes it visible or not visible).
A good example of how this could work is create a function for when the button is pressed and tell it to put the alpha or isVisible attribute to your choosing.
local menu = display.newGroup()
local playbtn = display.newImage("playbtn.png")
playbtn.x = 160
playbtn.y = 240
menu:insert(playbtn)
local optionsbtn = display.newImage("optionsbtn.png")
optionsbtn.x = 160
optionsbtn.y = playbtn.y + 40
menu:insert(optionsbtn)
local function play( event )
if (event.phase == "began") then
menu.alpha = 0
game.alpha = 1
end
end
playbtn:addEventListener( "touch", play)
When the play button is touched, we tell the menu group to become invisible and the game group to become visible. You can do anything you would like though, such as moving the group instead of make it invisible, and so on.
The code I have posted above is sloppy but shows the concept. If you have a fairly large game then it may be better to use one of the API listed above. It is all about personal preference really!
Hope this helps explain the state of “scenes” and “pages” in Corona! [import]uid: 71971 topic_id: 23291 reply_id: 93273[/import]