External GUI module issue, display objects not appearing in the right order

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.

GUI:insert(borderL) 

GUI:insert(borderR)

actually inserts them into the display group ‘GUI’

GUI.borderL = borderL   is just assigning a handle to the image and attaching it to the ‘GUI’ display object, not inserting it into that group.

I am guessing that is what you are wanting to do.

Thanks for your reply.

I will try that and see how I get on, I will let you know what happened in a moment, just got to change 39 lines of code, won’t take long…

I know this is hard to believe but even after a year of using Corona I haven’t used external modules for my display objects so I don’t know what to do here.

I’ve done as you suggested and inserted the objects into the GUI display group but I don’t know how to manipulate those objects in my other modules. I’m sure I tried this before and couldn’t find anything in the Corona docs that explained how you do this.

All I know is this, in one of my level screens to move the borderL I would do…

local GUI = require(“GUI”)

    mainGroup:insert(GUI)

GUI.borderL.x = 50

Which is wrong because the simulator returns a nil vale, but that’s all I can think of…

Can you give me the proper syntax to affect the display objects in an external module please?

Your help is most appreciated.

in your GUI module you can still attach the handles to the images as you originally had done. Then you will not get a ‘nil’ in the example you just posted.  It is just originally you had not been inserting them into the display group.

So in your GUI module you need to do both, do the ‘insert’ calls to make sure the image is ‘in’ that display group, and since you are going to need to manipulate some of those images individually, assigning the handle like you originally did  

GUI.borderLeft = borderLeft will work.  

Well there you go, I couldn’t find any info on this anywhere.

I will now do as you suggested and see what happens.

Thanks so much for your help :slight_smile:

Thanks again, this has answered my question and fixed my problem.

Hope your game turns out great.  Good luck!

Thank you, I do too I’ve put in 1000’s of hours, hope it pays off!

GUI:insert(borderL) 

GUI:insert(borderR)

actually inserts them into the display group ‘GUI’

GUI.borderL = borderL   is just assigning a handle to the image and attaching it to the ‘GUI’ display object, not inserting it into that group.

I am guessing that is what you are wanting to do.

Thanks for your reply.

I will try that and see how I get on, I will let you know what happened in a moment, just got to change 39 lines of code, won’t take long…

I know this is hard to believe but even after a year of using Corona I haven’t used external modules for my display objects so I don’t know what to do here.

I’ve done as you suggested and inserted the objects into the GUI display group but I don’t know how to manipulate those objects in my other modules. I’m sure I tried this before and couldn’t find anything in the Corona docs that explained how you do this.

All I know is this, in one of my level screens to move the borderL I would do…

local GUI = require(“GUI”)

    mainGroup:insert(GUI)

GUI.borderL.x = 50

Which is wrong because the simulator returns a nil vale, but that’s all I can think of…

Can you give me the proper syntax to affect the display objects in an external module please?

Your help is most appreciated.

in your GUI module you can still attach the handles to the images as you originally had done. Then you will not get a ‘nil’ in the example you just posted.  It is just originally you had not been inserting them into the display group.

So in your GUI module you need to do both, do the ‘insert’ calls to make sure the image is ‘in’ that display group, and since you are going to need to manipulate some of those images individually, assigning the handle like you originally did  

GUI.borderLeft = borderLeft will work.  

Well there you go, I couldn’t find any info on this anywhere.

I will now do as you suggested and see what happens.

Thanks so much for your help :slight_smile:

Thanks again, this has answered my question and fixed my problem.

Hope your game turns out great.  Good luck!

Thank you, I do too I’ve put in 1000’s of hours, hope it pays off!