Getting my head around the basics.

This may sound really stupid, but …

I’ve been using other software with HTML, etc so I am finding it difficult to understand the ‘structure’ of Corona.

I have an app that has a homepage of menu buttons.

I have the buttons - all good.

When a user clicks a button I want them to go to another ‘page’.

Do I set up pages and then open/close them or is everything static?

For example :

When a user clicks a button do I then have to hide all of my buttons and then make visible my text or rss feed?

Then when the user clicks a ‘back’ button hide the text and images and then load the menu buttons again?

I hope that makes sense.

Thanks in advance for any help.

[import]uid: 133106 topic_id: 23291 reply_id: 323291[/import]

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]

Hi kbegeman,

I really can’t thank you enough. I didn’t even know what I was looking for so I was going around in circles.

You explained everything perfectly and now I can move on. It was a very good explanation.

I’m not doing games, but more business apps. I know that Corona is mainly used for games, but I really like it cross platform capabilities.

I hope I haven’t made a mistake - time will tell.

All the best. [import]uid: 133106 topic_id: 23291 reply_id: 93506[/import]

Just doing my part! I am glad it helped!

Corona is a great tool for all sorts of apps, including business apps!

You can use a combination of the director class and groups as well to create cool pop ups and such on different scene’s. You can get pretty creative!

Best of luck! And if you have any other questions feel free to ask!

[import]uid: 71971 topic_id: 23291 reply_id: 93539[/import]

I found this template by Radamanthus very helpful when I was first starting out

http://developer.anscamobile.com/code/game-template

You can run that sample and edit it to your needs, start replacing items with your own menu images etc.

Edit: It has the director class integrated as mentioned above by kbegeman [import]uid: 31262 topic_id: 23291 reply_id: 93559[/import]