What are some of the best practices you guys use?

About to start my first project with Corona and I was wondering what are some of the practices you guys use when working with your own projects. For example:

1- How do you organize your project, folders and assets.

2- Do you use a lot of modules?

3- Any oop paradigm? and if so for what, enemies, player?

4- Any external libraries you always use? 

5- How do you organize your scene file?

6- Do you use some kind of “GameManager” file for constants like, current unlocked level, current currency, etc. 

Any help would be much appreciated, and feel free to add anything extra. 

1- How do you organize your project, folders and assets.

\ |-- build.settings |-- config.lua |-- main.lua |-- images/ -- Images folder, may have sub-folders |-- ifc/ -- Composer scene files (mostly sparse and calling modules to do heavy lifting) |-- scripts/ -- modules, helper scripts, etc. ... After this, it varies.

2- Do you use a lot of modules?

My games and apps are entirely modular.  I never write all-in-one-file games/apps.

 

3- Any oop paradigm? and if so for what, enemies, player?

I do not use OOP.  I do however have a strong modular organizatiom.

 

I am not against OOP in general, but IMHO"

 

A. Lua isn’t really an OOP language to anything OOP is forced.

 

B. Lua-ish OOP doesn’t fit w/ Corona because you cannot modify the metatables and metamethods of displyay.* objects w/o hosing them up.   Thus, you end up using tables and class objects and then they handle creating, managing, and destroying display objects.

 

All of this ends up being messy and prone to error.

 

C. You can follow a OOP paradigm using pure modules and intelligent design using pure display objects.  Additionally, you can attach fields and special methods to display objects, thus extending them in a very OOP way, which is much cleaner.

 

 

4- Any external libraries you always use? 

SSK.  Enough said.  (SSK 2 is in progress…)

 

5- How do you organize your scene file?

Will paste example below, but in short I prefer my own ‘improved’ layout and org.

 

6- Do you use some kind of “GameManager” file for constants like, current unlocked level, current currency, etc. 

Sorry, no answer for this one, I’m working on a system for this, but to date, I’ve done this per project.

A scene file as generated via EAT (this is my preferred layout)

-- ============================================================= -- Your Copyright Statement Goes Here -- ============================================================= -- filename here -- ============================================================= local composer = require( "composer" ) local scene = composer.newScene() ---------------------------------------------------------------------- -- Locals ---------------------------------------------------------------------- local centerX = display.contentCenterX local centerY = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local left = centerX - fullw/2 local right = centerX + fullw/2 local top = centerY - fullh/2 local bottom = centerY + fullh/2 ---------------------------------------------------------------------- -- Forward Declarations ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- Improved Scene Methods ---------------------------------------------------------------------- -- -- Tip: This composer template is slightly different from the "standard" template found here: -- https://docs.coronalabs.com/daily/api/library/composer/index.html#scene-template -- -- I have split the scene:show() and scene:hide() methods into these distinct sub-methods: -- -- \* scene:willShow() - Called in place of "will" phase of scene:show(). -- \* scene:didShow() - Called in place of "did" phase of scene:show(). -- \* scene:willHide() - Called in place of "will" phase of scene:hide(). -- \* scene:didHide() - Called in place of "did" phase of scene:hide(). -- -- I did this to help folks logically separate the phases and for those converting from storyboard.\* which -- had similar methods. -- ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- scene:create( event ) - Called on first scene open ONLY (unless -- the scene has been manually or automatically destroyed.) ---------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:willShow( event ) - Replaces the scene:show() method. This -- method is called during the "will" phase of scene:show(). ---------------------------------------------------------------------- function scene:willShow( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:didShow( event ) - Replaces the scene:show() method. This -- method is called during the "did" phase of scene:show(). ---------------------------------------------------------------------- function scene:didShow( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:willHide( event ) - Replaces the scene:hide() method. This -- method is called during the "will" phase of scene:hide(). ---------------------------------------------------------------------- function scene:willHide( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:didHide( event ) - Replaces the scene:hide() method. This -- method is called during the "did" phase of scene:hide(). ---------------------------------------------------------------------- function scene:didHide( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:destroy( event ) - Called automatically by Composer scene library -- to destroy the contents of the scene (based on settings and memory constraints): -- https://docs.coronalabs.com/daily/api/library/composer/recycleOnSceneChange.html -- -- Also called if you manually call composer.removeScene() -- https://docs.coronalabs.com/daily/api/library/composer/removeScene.html ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- Custom Scene Functions/Methods ---------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- -- This code splits the "show" event into two separate events: willShow and didShow -- for ease of coding above. function scene:show( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willShow( event ) elseif( willDid == "did" ) then self:didShow( event ) end end -- This code splits the "hide" event into two separate events: willHide and didHide -- for ease of coding above. function scene:hide( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willHide( event ) elseif( willDid == "did" ) then self:didHide( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

@roaminggamer

Thank you very much for your help, but I was wondering if you could explain SSK a little more, what exactly is it and where can I find it? 

I also noticed that you define some utility variables like centerX, centerY at the top of your scene, Isn’t it better to define them once in a separate utility file and require it, especially if there are several scenes in the project, or is this some kind of a copy/paste template you use? 

Hi this is the old SSK: http://github.com/roaminggamer/SSKLegacy

However, if you are new you don’t want to use it.  Using SSK while learning Corona, would be a little like learning to swim in the deep-end of the pool without a lifeguard.  

Also, as the notes say on the SSK Legacy page, I’m working on SSK 2 which will be part of EAT and much better suited for general use. 

1- How do you organize your project, folders and assets.

\ |-- build.settings |-- config.lua |-- main.lua |-- images/ -- Images folder, may have sub-folders |-- ifc/ -- Composer scene files (mostly sparse and calling modules to do heavy lifting) |-- scripts/ -- modules, helper scripts, etc. ... After this, it varies.

2- Do you use a lot of modules?

My games and apps are entirely modular.  I never write all-in-one-file games/apps.

 

3- Any oop paradigm? and if so for what, enemies, player?

I do not use OOP.  I do however have a strong modular organizatiom.

 

I am not against OOP in general, but IMHO"

 

A. Lua isn’t really an OOP language to anything OOP is forced.

 

B. Lua-ish OOP doesn’t fit w/ Corona because you cannot modify the metatables and metamethods of displyay.* objects w/o hosing them up.   Thus, you end up using tables and class objects and then they handle creating, managing, and destroying display objects.

 

All of this ends up being messy and prone to error.

 

C. You can follow a OOP paradigm using pure modules and intelligent design using pure display objects.  Additionally, you can attach fields and special methods to display objects, thus extending them in a very OOP way, which is much cleaner.

 

 

4- Any external libraries you always use? 

SSK.  Enough said.  (SSK 2 is in progress…)

 

5- How do you organize your scene file?

Will paste example below, but in short I prefer my own ‘improved’ layout and org.

 

6- Do you use some kind of “GameManager” file for constants like, current unlocked level, current currency, etc. 

Sorry, no answer for this one, I’m working on a system for this, but to date, I’ve done this per project.

A scene file as generated via EAT (this is my preferred layout)

-- ============================================================= -- Your Copyright Statement Goes Here -- ============================================================= -- filename here -- ============================================================= local composer = require( "composer" ) local scene = composer.newScene() ---------------------------------------------------------------------- -- Locals ---------------------------------------------------------------------- local centerX = display.contentCenterX local centerY = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local left = centerX - fullw/2 local right = centerX + fullw/2 local top = centerY - fullh/2 local bottom = centerY + fullh/2 ---------------------------------------------------------------------- -- Forward Declarations ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- Improved Scene Methods ---------------------------------------------------------------------- -- -- Tip: This composer template is slightly different from the "standard" template found here: -- https://docs.coronalabs.com/daily/api/library/composer/index.html#scene-template -- -- I have split the scene:show() and scene:hide() methods into these distinct sub-methods: -- -- \* scene:willShow() - Called in place of "will" phase of scene:show(). -- \* scene:didShow() - Called in place of "did" phase of scene:show(). -- \* scene:willHide() - Called in place of "will" phase of scene:hide(). -- \* scene:didHide() - Called in place of "did" phase of scene:hide(). -- -- I did this to help folks logically separate the phases and for those converting from storyboard.\* which -- had similar methods. -- ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- scene:create( event ) - Called on first scene open ONLY (unless -- the scene has been manually or automatically destroyed.) ---------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:willShow( event ) - Replaces the scene:show() method. This -- method is called during the "will" phase of scene:show(). ---------------------------------------------------------------------- function scene:willShow( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:didShow( event ) - Replaces the scene:show() method. This -- method is called during the "did" phase of scene:show(). ---------------------------------------------------------------------- function scene:didShow( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:willHide( event ) - Replaces the scene:hide() method. This -- method is called during the "will" phase of scene:hide(). ---------------------------------------------------------------------- function scene:willHide( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:didHide( event ) - Replaces the scene:hide() method. This -- method is called during the "did" phase of scene:hide(). ---------------------------------------------------------------------- function scene:didHide( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- scene:destroy( event ) - Called automatically by Composer scene library -- to destroy the contents of the scene (based on settings and memory constraints): -- https://docs.coronalabs.com/daily/api/library/composer/recycleOnSceneChange.html -- -- Also called if you manually call composer.removeScene() -- https://docs.coronalabs.com/daily/api/library/composer/removeScene.html ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- Custom Scene Functions/Methods ---------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- -- This code splits the "show" event into two separate events: willShow and didShow -- for ease of coding above. function scene:show( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willShow( event ) elseif( willDid == "did" ) then self:didShow( event ) end end -- This code splits the "hide" event into two separate events: willHide and didHide -- for ease of coding above. function scene:hide( event ) local sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willHide( event ) elseif( willDid == "did" ) then self:didHide( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

@roaminggamer

Thank you very much for your help, but I was wondering if you could explain SSK a little more, what exactly is it and where can I find it? 

I also noticed that you define some utility variables like centerX, centerY at the top of your scene, Isn’t it better to define them once in a separate utility file and require it, especially if there are several scenes in the project, or is this some kind of a copy/paste template you use? 

Hi this is the old SSK: http://github.com/roaminggamer/SSKLegacy

However, if you are new you don’t want to use it.  Using SSK while learning Corona, would be a little like learning to swim in the deep-end of the pool without a lifeguard.  

Also, as the notes say on the SSK Legacy page, I’m working on SSK 2 which will be part of EAT and much better suited for general use.