Modules, Sprites, Storyboards And Layering

Hi, Folks-

I would really appreciate some pointers towards solving a problem I’m having. Because the code is so specific, I’m hoping I can find a solution by presenting some general information first, and if necessary, will include  actual code later.

I’m building an app using the storyboard module, and in this app I’m calling in another module that displays graphics to be used as buttons. These buttons are meant to remain onscreen consistently throughout the app’s lifetime, through all scene changes, so I’m unconcerned (perhaps erroneously) about the global nature of the module. I’m requiring this button module in main.lua, and the buttons are showing up where they are supposed to, and working as they are supposed to. 

The problem I’m running into is layering. My background graphics, which are being brought in as display.newRect objects, and inserted into the scene’s self group, are layering appropriately throughout scene changes. However, my sprite animations (which are draggable) overlay the button graphics, which is undesirable.

I’m building my animated sprites by creating a spritesheet as per the “simple” method (described in Jonathan Beebe’s article- http://www.coronalabs.com/blog/2012/03/06/image-sheets-image-groups-and-sprites/), and then completing the process by declaring the sprite via “display.newSprite(imageSheet, sequenceData).”

What I’ve noticed is that the objects that layer properly are the ones that have been successfully inserted into the scene’s self view (local group = self.view), after being instantiated as “newRect” objects. If I try to insert my sprite animations into the self view, I’m unsuccessful.

Things I have tried, unsuccessfully-

  1. Creating a new display table for the buttons, and inserting the buttons into this table, and using the “toFront” function, calling the module both from the main.lua file, as well as trying calling it from individual scene files, to no avail in either case.

  2. Loading the spritesheet into a display.newRect object, and inserting that into the self.view group. This screws up my sequenceData possibilities, though.

Any help, tips, pointers, etc. would be greatly appreciated! And I hope you’ll forgive me for using the term “object” where “table” is probably more appropriate. It’s a leftover Flash habit.  :slight_smile:

Thanks! 

Hi @tom12,

One option you could try is to put all of your “main buttons” into a separate display group on the overall “stage”. Then, pass a reference to that group to every Storyboard scene (or if it’s global, you can just reference it directly). After the rest of your secondary scene loads, bump that “main” group to the front of the stage. Probably the easiest way would be to just re-insert the group on the stage, which should push it to the front.

While on the topic, here’s a more current tutorial on sprites (same basic thing as the one you found, but anyway, here it is):

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Hope this helps a bit,

Brent

Hi, Brent-

Thanks for the reply. I’ll try and play with your suggestion and see if that works- if I’m reading you correctly, what I think you are saying is

  1. ditch the external module

  2. Re-create it within the main.lua file by creating a (global) display group containing the buttons

  3. Use either the toFront method in each scene to push them to the front or re-insert them at the point in each scene’s code where they’ll naturally wind up at the top of the graphic stack

Anyway, if I’m misreading you, could you let me know?

The only other way I thought I might use your suggestion is to create a display group within the module to insert the images in, and then insert that group via step 3 as mentioned above. Not entirely sure how that would work, or if it’s necessary, but… hmm.

btw- read your sprite tutorial some time ago, so thanks for the re-reference. It was one of the first tutorials I read when starting working with Corona and it helped a great deal.

Tom

Hi Tom,

Yep, that’s how I envision it working… create the “global” buttons in main.lua and push them to the front of the stage in each scene.

Brent

P.S. Good to hear that my sprite tutorial was helpful to you. :slight_smile:

Hi, Brent-

Quick followup- Just solved the issue inside the module, as I preferred to handle all button issues inside one file. Simply loaded all the buttons into a new display group inside the module, and called the toFront on enterScene. Voila! Working smoothly. 

Thanks! Your suggestions were a great help.

Tom

Hi @tom12,

One option you could try is to put all of your “main buttons” into a separate display group on the overall “stage”. Then, pass a reference to that group to every Storyboard scene (or if it’s global, you can just reference it directly). After the rest of your secondary scene loads, bump that “main” group to the front of the stage. Probably the easiest way would be to just re-insert the group on the stage, which should push it to the front.

While on the topic, here’s a more current tutorial on sprites (same basic thing as the one you found, but anyway, here it is):

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Hope this helps a bit,

Brent

Hi, Brent-

Thanks for the reply. I’ll try and play with your suggestion and see if that works- if I’m reading you correctly, what I think you are saying is

  1. ditch the external module

  2. Re-create it within the main.lua file by creating a (global) display group containing the buttons

  3. Use either the toFront method in each scene to push them to the front or re-insert them at the point in each scene’s code where they’ll naturally wind up at the top of the graphic stack

Anyway, if I’m misreading you, could you let me know?

The only other way I thought I might use your suggestion is to create a display group within the module to insert the images in, and then insert that group via step 3 as mentioned above. Not entirely sure how that would work, or if it’s necessary, but… hmm.

btw- read your sprite tutorial some time ago, so thanks for the re-reference. It was one of the first tutorials I read when starting working with Corona and it helped a great deal.

Tom

Hi Tom,

Yep, that’s how I envision it working… create the “global” buttons in main.lua and push them to the front of the stage in each scene.

Brent

P.S. Good to hear that my sprite tutorial was helpful to you. :slight_smile:

Hi, Brent-

Quick followup- Just solved the issue inside the module, as I preferred to handle all button issues inside one file. Simply loaded all the buttons into a new display group inside the module, and called the toFront on enterScene. Voila! Working smoothly. 

Thanks! Your suggestions were a great help.

Tom