Can you recommend a sample project that shows good practices?

HI all,

As part of learning Corona, I would like to see how the pros organise their code. In particular, I am interested in knowing how to best manage the memory when a scenes are created/shown/hidden/destoryed. I found few free templates in the market. I am not sure which one would be the best to download to learn from.

So if you know of a good one, please put forward your suggestions.

Kind regards.

Roaminggamer has written several articles about this.  I can’t find them at the moment but you could check out his sample games in the Corona Marketplace.  I think that skiing, birdclimb and lava all use scenes.

Thanks @sporkfin for providing the link and thanks @Roaminggamer for providing the projects.

I downloaded FloorIsLava and started looking into it. I noticed that the created display objects are put into a container (during the show event)  and then the container is “removed” at the “hide” event. Will removing the container also remove and free the memory for all the objects it contains? Up till now I was removing the objects individually. This meant that I had to declare a variable outside the events for each and every object I added so that  I can access it and remove it at the end.

I believe Items that are inserted to the scene group are removed when the scene is destroyed.  Is the container inserted into the screen group at some point?

The way of handling objects in scenes is not consistent. For example:

In splash.lua:

Few objects are added to the sceneGroup but never removed.

In about.lua:

In function (scene:willShow) a new group is removed, recreated then inserted into the scene group.

Then objects are inserted into the content group.

 display.remove(content) content = display.newGroup() sceneGroup:insert(content)

In home.lua:

a content group is created in the function (scene:willShow) and added to the sceneGroup.

In function (scene:didHide) the content group is removed.

I am sure Roaminggamer had a good reason for using different methods in different scripts but I am still not sure on weather I should remove objects individually or not. 

If you find any please paste the url links here. Thanks so much :slight_smile:

I found the following paragraph regarding groups and the objects they contain:

Removing Groups Groups can be removed via the display.remove() or object:removeSelf() functions. When you do so, all children in the group will be removed as well. However, you must still manually remove variables or other references associated with these children, otherwise they will not be freed from memory. For more details, see the Display Objects guide.

So  it seems that I still have to assign nil to the variables even if I included the objects in a group.

The paragraph above is from this page:

https://docs.coronalabs.com/guide/graphics/group.html

Also the Display Objects Guide has a useful section:

https://docs.coronalabs.com/guide/media/displayObjects/index.html#remove

The best apps to look at for organizational purposes are the PonyWolf apps they built for us as examples. See:
http://docs.coronalabs.com/guide/programming/index.html

And scroll down to the three examples at the bottom. PonyWolf is one of our more successful studios and has created some very useful libraries for our developers to use. We worked with them to vet the project and suggest what we think the best structure is.

Rob

Thanks Rob for the link. 

Some of them even have video tutorials  :) .