Corona Game Template in Lua

This is a template I threw together for the Corona SDK from Ansca Mobile. Since Lua is not a language most people are familiar with, I figured I’d throw together some sample code for Corona and share what I learned so far with the rest of the Corona SDK community by including the template here.

The template includes example code for:

  • Display groups
  • Orientation and accelerometer
  • Touch with buttons
  • File reading
  • Example level file for scripting game play

The template separates functionality into modules for an object oriented approach. I’m still learning the techniques for Lua, so if you notice a better way to do it, please don’t hesitate to let me know in the comments below. Some things in the template are not the best way to accomplish some things, but should give people a good idea on best practices of software design. This will also with work Corona’s Game Edition.

If you find the template useful, take a look at some of our current applications to support us. It’d mean a lot.

Download the Template Code

Also, check out the links on the side. Thanks!

14 Comments on “Corona Game Template in Lua

  1. Thanks for the Corona Game Template Code. But how does one use it? I downloaded “CoronaGameTemplate.zip”. I unzip that and get “CoronaGameTemplate.zip.cpgz”. I double click that and get “CoronaGameTemplate.zip”. I unzip that and get “CoronaGameTemplate.zip.cpgz”. Is this some kind of joke?

  2. Oh by the way. I could download the template and to be sure… it’s not a joke! It’s very helpful. Thank you for your time and effort.

    • Thanks. Glad you like it. Just figured since I banged my head enough trying to make Lua more like OOP that others were doing the same. I’ll be updating this soon to put in some more things that I’ve learned as we wrap up our game. Thanks again!

  3. Would love to see that updated version of this, I placed a link to this page on the Forum at Corona…. I couldn’t believe you hadn’t shared this with the ansca website! It’s great and would help beginners understand so much! Calling other .lua files or modules is such a hot topic of confusion for people in the Forums. Thanks for your help! Derek

    • Not a problem. I posted the link deep within another conversation so I guess not a lot of people saw it. I’ll make sure and post it as a separate post when I get a chance to update it.

      Thanks a ton!

  4. Hi.
    I’ve started to set my game up using this but I’m starting to get confused with what code should be going where.

    I have a working prototype Menu with animated BG (in a single lua file) and separate Title / Character image as well as menu buttons. These buttons call slide over semi transparent screens.

    Now these currently work in the single function / file and I’m getting close to having them work in the MVC but I getting a little lost.
    How do I prevent things being constantly called and how do I get rid of things once they are off screen and other questions…??
    Any help would be appreciated.

    • When a menu button is selected, you can have a Lua class load a display group that contains a bunch of images on the screen. Then you can have another function in that same Lua class that hides that display group when it’s no longer needed. All your images should be in display groups so that it’s easier to manage and hide things easier. Otherwise, you have to hide all the individual pieces.

  5. I was wondering if you had and tutorial file for this template??
    I’m plodding my through it by creating a game but I’m a little lost in some areas.

    Cheers

    • The template will be updated soon. I’m working on a few programs with it, and will incorporate those additions back into the template. Thanks for the interest!