We want this as well. If you want to use the Composer for business apps you are going to end up with the same scene (file) used to populate different things.
Consider for example a blog app. You may have a “posts-list.lua” and a “single-post.lua”. If you want to move directly from a single-post to another single-post, you need to duplicate your single-post.lua. Not cool. Not DRY.
The implementation should be quite easy anyway. If you pass a string to the composer.gotoScene() function, it does a require. If you pass it a table, it uses that table instead. Something as simple as this:
[lua]
function composer:gotoScene( scene, options )
local scene_table
if type(scene) == “string” then
scene_table = require( scene )
elseif type(scene) == “table” then
scene_table = scene
end
…
end
[/lua]
Â
Of course you need to check if you have previously loaded the same table before (so you don’t call create, etc) but I bet the composer is already doing that in some way.
Then you can do a composer.newScene() outside a .lua file, organise the code to be reusable and don’t repeat yourself.
Today I have read this on the Daily Builds:
- Composer: Fixing a error when defining multiple scenes inside the same lua file. Casenum #32231, #32168
I wonder if there is already a way to do this.
Could somebody from Corona explain it? I couldn’t find any more information about it.