Question about composer scene organization

Apologies for the very basic question.

I’m working on a fairly simple game to try and learn Corona and Composer (Which seem awesome btw).

I have a fairly simple game flow:

Main Menu

Start Game

-Game Scene 1

-Game Scene 2

For the sake of simplicty, let’s assume Game Scene 1 is a dungeon and Game Scene 2 is a forest. Those scenes have slightly different functionality.

On top of both Scene 1 and Scene 2 I want a persistent UI showing things like name, health, etc.

I’m not exactly sure how to best organize that.

My first stab was to put the persistent UI as an overlay and then just use gotoScene(1) and gotoScene(2).

However, the gotoScene functionality wipes out the overlay.

My next thought is to do the same thing but just have ONE scene and just load and unload assets and funcitonlaity, but that seemed weird to me.

So basically what I’m curious about is what’s the “right way” to have a persistent UI on top of different types of game funtionality in Corona?

Thanks!

Do this:

  1. In main.lua create two groups:

    _G.underlayContent = display.newGroup() _G.overlayContent = display.newGroup()

  2. Now, make sure ‘underlayContent’ stays below all content and ‘overlayContent’ above everything.

    – always underneath everything else _G.underlayContent.enterFrame = _G.underlayContent.toBack Runtime:addEventListener( “enterFrame”, _G.underlayContent) – always over everything else _G.overlayContent.enterFrame = _G.overlayContent.toFront Runtime:addEventListener( “enterFrame”, _G.overlayContent)

  3. Now, put any content you want ‘behind’ in ‘underlayContent’ and anything you want to be on top in ‘overlayContent’.

These scenes are outside the composer group system and won’t interact, thus they will always be behind / in-front.

Thank you so much for the quick and helpful reply!

I’ll give that a shot.

In composer, any display objects that you **DO NOT** put into the scene’s view group sits on top of other composer scenes. This is called “HUD” mode and the purpose was you could have your UI elements (health, inventory, etc.) sit on top of your actual composer scenes.

You can create those elements in main.lua and put them in a display.newGroup() so you can transition them on and off screen when you need them and not have them connected to the composer scenes.

Rob

Thanks Rob. This makes lots of sense.

You and roaminggamer have already stealth-helped me a lot with your previous posts and these don’t disappoint. Thanks for taking time to help me out!

Rob,

I just did what you suggested like this:

in main.lua

local HUD = display.newGroup()

–Create a “health meter” image which should appear above all scenes

local meter = display.newImage( “images/progress_bar_12.png” )

meter.anchorX = 0

meter.anchorY = 1

meter.x, meter.y = 20, display.contentHeight-20

HUD:insert(meter)

and then later

composer.gotoScene(“main_game_loop”, options)

then within main_game_loop.lua I do this

composer.gotoScene(“main_menu”, options)

and finally in main_menu.lua I do this

composer.gotoScene(“main_game_loop”, options)

and the result is that the health bar stays in front of the scene transitions at all time.

roaming… I didn’t try your suggestion yet, but I suspect that would also work. I was just lazy and Rob’s seemed easier to try :stuck_out_tongue:

thanks a lot guys! I started writing game code before the internet was around and so I often forget that asking people who know more can save hundreds of hours which I think you guys just did!

Do this:

  1. In main.lua create two groups:

    _G.underlayContent = display.newGroup() _G.overlayContent = display.newGroup()

  2. Now, make sure ‘underlayContent’ stays below all content and ‘overlayContent’ above everything.

    – always underneath everything else _G.underlayContent.enterFrame = _G.underlayContent.toBack Runtime:addEventListener( “enterFrame”, _G.underlayContent) – always over everything else _G.overlayContent.enterFrame = _G.overlayContent.toFront Runtime:addEventListener( “enterFrame”, _G.overlayContent)

  3. Now, put any content you want ‘behind’ in ‘underlayContent’ and anything you want to be on top in ‘overlayContent’.

These scenes are outside the composer group system and won’t interact, thus they will always be behind / in-front.

Thank you so much for the quick and helpful reply!

I’ll give that a shot.

In composer, any display objects that you **DO NOT** put into the scene’s view group sits on top of other composer scenes. This is called “HUD” mode and the purpose was you could have your UI elements (health, inventory, etc.) sit on top of your actual composer scenes.

You can create those elements in main.lua and put them in a display.newGroup() so you can transition them on and off screen when you need them and not have them connected to the composer scenes.

Rob

Thanks Rob. This makes lots of sense.

You and roaminggamer have already stealth-helped me a lot with your previous posts and these don’t disappoint. Thanks for taking time to help me out!

Rob,

I just did what you suggested like this:

in main.lua

local HUD = display.newGroup()

–Create a “health meter” image which should appear above all scenes

local meter = display.newImage( “images/progress_bar_12.png” )

meter.anchorX = 0

meter.anchorY = 1

meter.x, meter.y = 20, display.contentHeight-20

HUD:insert(meter)

and then later

composer.gotoScene(“main_game_loop”, options)

then within main_game_loop.lua I do this

composer.gotoScene(“main_menu”, options)

and finally in main_menu.lua I do this

composer.gotoScene(“main_game_loop”, options)

and the result is that the health bar stays in front of the scene transitions at all time.

roaming… I didn’t try your suggestion yet, but I suspect that would also work. I was just lazy and Rob’s seemed easier to try :stuck_out_tongue:

thanks a lot guys! I started writing game code before the internet was around and so I often forget that asking people who know more can save hundreds of hours which I think you guys just did!