Create scene OR did enter scene

Good day, to all thriving Corona developers.

It is my understanding that the “scene:create” function does any heavy lifting of graphic resources or table construction or OOP object construction BEFORE attempting to display graphic content.

And the “scene:didEnter” displays these pre-handled resources.

My confusion today concerns the placement of the following:

–CREATE AN IMAGE SHEET & DISPLAY AN IMAGE FRAME

local options = { width = 142, height = 234, numFrames = 15, sheetContentWidth = 710, sheetContentHeight = 702 } local spriteSheet = graphics.newImageSheet( "images/CardImageSheet.png", options) local card1 = display.newImageRect(sceneGroup, spriteSheet, 1, 142,234) card1.x = centerX card1.y = centerY

In my mind, the spriteSheet and options should be handled in the create function, and the displaying of card1 is handled in the “did enter” function.

To be safe, I forward referenced all variables, at the head of my playGUI.lua file, but the card only displays, when all of the above code is in either the create, or all the code is in the didEnter.

Does this not, “in theory” burden the didEnter function with heavy lifting that could have been handled in the create function?

Anyone care to explain this for the billionth time? :slight_smile:

Thanks.

Chris

Chris, 

I like to think of it this way. The scene:create function is called before you actually see anything. Think of it like this. I have a picture I want to show you. I could show you a blank piece of paper and then draw the picture. Or, I could draw a picture on a blank sheet of paper and then show it to you. The same sense can be applied to Composer. The scene:create draws everything before showing it to you. You can actually test this out pretty easily. Create a simple display object in the scene:create function. When you run this in the simulator, the object will appear immediately. If you create the same object in the show function, it won’t actually appear until after the scene has been shown on the screen. Display objects in general should be created in the scene:create function. Then when the scene is loaded you see everything. If you do a little of both you’ll end up with an incomplete scene being loaded and then other objects being added with a slight delay. It won’t look crisp. Once the scene:create function has loaded everything on the screen, you can use the show function to start timers, audio, animations…etc. 

LOUD AND CLEAR! :slight_smile: 100%!

One other thing to ponder…  Since scene:create() does it’s work off screen and once constructed, it moves on screen, then scene:show()'s “did” phase fires, letting you know it’s now on screen.

If your imageSheet is used to spawn critters that are going to be created “after” the scene is on the screen, then you are going to need to be able to access the imageSheet in functions other than scene:create().  graphics.newImageSheet() doesn’t create anything visual, you may want to consider creating the imageSheet in the main chunk so it’s visible throughout the whole scene.

Rob

Thanks, Rob,

  1. for adding further insight, and

  2. for having the “Miracle Man” acknowledging me personally! :slight_smile:

I plan on sticking around.

Thank you all, so far, for proving this Corona Community truly is inspiring!

Chris

Chris, 

I like to think of it this way. The scene:create function is called before you actually see anything. Think of it like this. I have a picture I want to show you. I could show you a blank piece of paper and then draw the picture. Or, I could draw a picture on a blank sheet of paper and then show it to you. The same sense can be applied to Composer. The scene:create draws everything before showing it to you. You can actually test this out pretty easily. Create a simple display object in the scene:create function. When you run this in the simulator, the object will appear immediately. If you create the same object in the show function, it won’t actually appear until after the scene has been shown on the screen. Display objects in general should be created in the scene:create function. Then when the scene is loaded you see everything. If you do a little of both you’ll end up with an incomplete scene being loaded and then other objects being added with a slight delay. It won’t look crisp. Once the scene:create function has loaded everything on the screen, you can use the show function to start timers, audio, animations…etc. 

LOUD AND CLEAR! :slight_smile: 100%!

One other thing to ponder…  Since scene:create() does it’s work off screen and once constructed, it moves on screen, then scene:show()'s “did” phase fires, letting you know it’s now on screen.

If your imageSheet is used to spawn critters that are going to be created “after” the scene is on the screen, then you are going to need to be able to access the imageSheet in functions other than scene:create().  graphics.newImageSheet() doesn’t create anything visual, you may want to consider creating the imageSheet in the main chunk so it’s visible throughout the whole scene.

Rob

Thanks, Rob,

  1. for adding further insight, and

  2. for having the “Miracle Man” acknowledging me personally! :slight_smile:

I plan on sticking around.

Thank you all, so far, for proving this Corona Community truly is inspiring!

Chris