Easy Screen Management in Corona

When I first began developing with the Corona SDK, screen (aka “scene”) management and code organization was probably most difficult thing to wrap my head around and get used to.

At first glance, and at second glance (after looking at the included Corona examples), I thought: Is an entire project really supposed to fit into this ONE main.lua text file?!

I did look up external modules in the API documentation, but I didn’t really get it. Because I was still on my 30-day trial and anxious to get started, I stopped worrying about modules and actually created my first game all within ONE main.lua file!

Towards the end of development, it was actually pretty stressful navigating around the enormous text file. I’ve since discovered BBEdit where it’s easy to find functions with the simple drop-down menu, but even with that, you’re still likely to get lost in a single text file if that’s where your entire app/game is.

Learning From Experience

By the time I was ready to work on the next game1, I knew I had to figure out a better way to not only organize the code, but to manage the different screens. I also wanted it to be as easy and as effective as possible.

So our second game had an “okay” screen management/code organization method in place, and by the time our third release was finished, my little “system” had become pretty refined.

I personally believe it is the easiest possible way to effectively manage screens in a Corona project2. That is, until some kind of IDE or screen editor comes out in a later release (personally, I don’t mind if that never happens, I like BBEdit).

The Corona Project Template

I created an example that contains three files:

  • main.lua
  • screen1.lua
  • cheat-sheet.txt

You can download the project template here. It contains your main project file, an example screen template that you can duplicate for as many screens (or “scenes”) you need in your app, and a “cheat sheet” text file that’ll walk you through all the steps that need to be accomplished to add a new screen to your app (only 5 steps).

I recommend you study the lua files, read the comments, and get a feel for how the “system” works. Once you’ve looked at the lua files, the cheat sheet should further clarify everything.

Something to keep in mind is that the template is just that, a template. It’s not a working example. If you were to build it, it wouldn’t compile without errors because it’s incomplete. However, the comments within each of the files as well as the cheat sheet should give you some pretty good insight into how everything fits together.

Know of a Better Way?

Are there easier, better ways to manage screens and organize code in a Corona project? Probably, but I haven’t discovered a quicker/easier method of doing so. If you have one, visit this article’s discussion thread and let me know about it!

http://cl.ly/2ito

Please use the thread above to also ask any questions you have, if you need clarification on how something works, or if you have trouble incorporating it into your project. I receive an email notification whenever someone replies to the thread, so I’ll be sure to respond.


  1. Dragon’s Keep was our second release. 

  2. All of our apps now utilize this same simple scene management system. 

posted: October 6, 2010