Hi all
I’m not exactly a newbie, I’ve been working on my game (full time) for a year now, but I feel that this is a newbie problem.
I’ve have a graphical user interface that is used throughout my entire game (apart from the menu) so I’ve created a separate module for it.
I understand that each time a display object is created it is put on top of the previous one, visually.
GUI.lua
local GUI = display.newGroup()
local borderL = display.newImageRect( “images/leftBorder.png”, 100,617 )
borderL.x = 50; borderL.y = _H*0.5
local borderR = display.newImageRect( “images/rightBorder.png”, 100,617 )
borderR.x = _W-50; borderR.y = _H*0.5
…
GUI.borderL = borderL
GUI.borderR = borderR
…
Return GUI
So in theory borderR will appear on top of borderL
I thought it would be a simple matter of inserting GUI into my main display group…
Level1.lua
function scene:enterScene(event)
local mainGroup = self.view
local GUI = require(“GUI”)
mainGroup:insert(GUI)
I don’t know why but the order in which I created the display objects in GUI.lua is now ignored, I have 39 objects in there and they have to be displayed in the proper order.
The only way I’ve managed to fix the order issue is to insert the GUI objects into my mainGroup one at a time…
mainGroup:insert(GUI.borderL)
mainGroup:insert(GUI.borderR)
… and so on…
As you can appreciate I now have 39 lines of code in every level for the GUI objects which seems to negate the whole idea of creating an external module in the first place.
Can somebody explain the correct way of doing this as I’m about to create another 20 levels for my game and don’t want to have to insert 39 lines of code into every one of them unnecessarily.
Many thanks in advance.
