Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Can you recommend a sample project that shows good practices?
Started by ammar71 Nov 17 2019 11:43 AM

8 replies to this topic
app templates market sample apps code organisation

Best Answer Rob Miracle , 19 November 2019 - 03:53 PM

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 77 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 669 posts
  • Corona SDK

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.


  • Alan PlantPot and AngelaMcCall like this

[TOPIC: post.html]
#3

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 77 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 669 posts
  • Corona SDK

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?



[TOPIC: post.html]
#5

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 77 posts
  • Corona SDK

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. 


  • AngelaMcCall likes this

[TOPIC: post.html]
#6

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 42 posts
  • Corona SDK

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.

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



[TOPIC: post.html]
#7

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 77 posts
  • Corona SDK

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



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,400 posts
  • Enterprise

  Best Answer

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


  • ammar71 and plicatibu like this

[TOPIC: post.html]
#9

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 77 posts
  • Corona SDK

Thanks Rob for the link. 

Some of them even have video tutorials  :) .




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: app templates, market, sample apps, code organisation