• Home
  • Contact
  • Careers
  • Socialize With Us:
  • Send us Mail
  • Follow us on Twitter
  • Join our Facebook Group
  • /
  • Linkedin
  • /
  • Vimeo Videos
  • /
  • Youtube
  • /
  • RSS Feed
  • Search Site

  • About UsAwards & Bio
  • PortfolioOur Latest Work
  • TrainingTips & Tutorials
  • BlogGreat Articles

You are here: Home / Training / Screencast Tutorials / Corona SDK for Mobile Development

Corona SDK for Mobile Development

Category: Screencast Tutorials     |     Tags: Games, Mobile

Developing iOS apps using CocoaTouch and XCode is great. Creating games however is a challenge.The tools are just geared to app development I think.

Developing Java-based Android games seems pretty horrible all around. Java is great (powerful but not easy), but the code-test-code development cycle leaves much to be desired.

Luckily there are 3rd party SDKs that create native iOS and also native Android projects geared for gaming. One of those is the Corona SDK from AnscaMobile.

Benefits of Corona SDKfor iOS/Android Development (In AnscaMobile’s words);

  • Build Apps 10x faster – Corona’s framework dramatically increase productivity. Tasks like animating objects in OpenGL or creating user-interface widgets take only one line of code, and changes are instantly viewable in the Corona Simulator. You can rapidly test without lengthy build times.
  • Same code, multiple stores – Corona is the only complete solution for developing across platforms, OS versions, and screen sizes. You can write once and build to iOS, Android, Kindle Fire or Nook Color at the touch of a button — Corona will automatically scale your content across devices from phones to tablets.
  • Simple, powerful APIs – Make use of advanced features using just a few lines of human-friendly code. For instance, you can implement realistic physics in your game with just five lines! Corona’s ease of use is what allows developers from indies to major studios to create #1 chart-topping apps, games, and eBooks.
  • Create engaging experiences – Say goodbye to cookie-cutter apps. Whether you’re creating branded apps, graphically rich games, or interactive eBooks, Corona gives you everything you need to go beyond the ordinary. It’s easy to make your apps behave and look exactly how you want them to.
  • Cut costs. Monetize faster – Corona enables you to produce top titles without big studio budgets. And thanks to Corona’s integrated support for in-app purchases, banner ads, and offer-based virtual currency, you can monetize faster and easier than ever before.
  • Join developers like you – Corona boasts a very generous and knowledgeable community, a plethora of 3rd party tools, as well as a shared code repository where users can download and share helpful libraries and snippets with one another. We also have 347 Corona SDK studios across 47 countries worldwide

Pro’s and Con’s of Corona (In my words)

I have used Corona SDK for about 5 hours. I’m new.

  • Lua is very very fast.
  • The code-test-code cycle is the best setup I’ve ever seen. Its so fast, just save your latest lua file and *poof* the project compiles and growl (on Mac) shows an error or not and your project is already running with debug output. (Now if I can just get the LDT IDE to handle debugging. I can, soon!)
  • Lua is not OOP. Corona is not component based. Without built-in OOP or built-in component based gaming (like Unity for example), development with Corona leaves much to be desired.
  • Its 2D only (good or bad, depending on your preference)
  • No great IDE yet.
  • Graphics are raster-based - So its a fast, but not easily reusable graphics pipeline.
  • Compared to HTML5 it has good multimedia capabilities. Compared to Flash it has horrible multimedia capabilities
Developing one code-base for multiple platforms (iOS/Android) is great. As Leetr.com mentions;
  • Marketing dollars – instead of marketing the game on two platforms separately, we can do it at the same time
  • Momentum – word of mouth dictates that downloads on one platform will possibly translate into downloads on the other
  • Maintenance - we’d rather be working on the next game, than debugging two separate platforms
  • Laziness - Corona SDK has a lot of modules already built in, ie Facebook, OpenFeint

Getting Setup

The steps to get started are to download the Corona SDK, choose your favorite text editor (I’m using Lua Development Toolkit), and run Corona’s Simulator on one of the sample projects to prove you’ve got it all setup properly.

We’ll show the provided ‘Bridge’ project which is a physics demo of some circles falling on a monkey-bridge.

Here are the links to get setup and publish a sample project;

  1. Download the free, unlimited-use Corona ‘Trial’ From AnscaMobile.
  2. Download the free, standalone Lua Development Toolkit (LDT) IDE from Koneki.
  3. Run LDT. You use LDT to setup the project and edit the code, but NOT for Corona code completion, NOT to compile and NOT to debug. I’m confident that all of that is possible, but I’m not yet sure how.
  4. Right-Click the ‘Script Explorer’ and choose ‘New Lua Project’
  5. Name it ‘Bridge’, choose ‘Create Project…’ and point to local url on your machine for ‘CoronaSDK/SampleCode/Physics/Bridge/’ where you installed the SDK.
  6. Open ‘CoronaSDK/SampleCode/Physics/Bridge/main.lua’, by clicking it in the ‘Script Explorer’. Don’t edit it. Just look at it.
  7. Run the ‘CoronaSDK/CoronaTerminal.app’ (on Mac). It will open terminal and also the Corona Simulator.
  8. In the Corona Simulator choose ‘File -> Open…’ and choose ‘CoronaSDK/SampleCode/Physics/Bridge/’. This will run the Bridge project in the Corona Simulator (an onscreen iPad emulator) and show any debugging output in the terminal.
  9. Done.
  10. Now without closing the Corona Simulator or the Corona Terminal, edit the ‘CoronaSDK/SampleCode/Physics/Bridge/main.lua’ file. Add the line ‘print (“hello”);’  without outer quotes and save the file. Upon save the Corona Simulator and Corona Terminal will automatically re-run the project. Nice!

Hello World Project

Typically a Hello World program illustrates the quickest way to get anything (such as text) onto the screen and publishing (or compiling) without errors.

In this post I have also added a few things. We see classpathing (‘com.rmc….’), a custom super class, and examples of publicity and privacy for class members.

The Project Output

Here is the example running. Corona’s included device emulator (“Simulator”) is in iPad mode. Other modes are available.

Debugging: Corona shows your debugging output too (using Terminal for example on Mac OSX). Simulator & Debug Window

The Project File Structure

Corona has many great demo projects included. Each project sits in its own folder. All files for a project sit within without using subfolders. I read on several blogs that while the Corona simulator allows for subfolders, that iPhone and/or Android does not. There are workarounds.

A development environment that does not allow for folders is ridiculous & irresponsible. – Me.

You’ll see my examples all feature a folder structure. For now, they run in the Simulator and that’s all I care about. I assume full folder support will come at some point in the future. If not, you can remove the subfolders from my demos before you start your final code.

HelloWorldOOP File Structure

Document Class

Lua doesn’t support OOP. Corona doesn’t support OOP. However it is possible to fake it.

I learned a good bit from Ludicroussoftware.com’s post, and JesseWarden’s post. There is more info about scope too.

The document class is the main entry point for your application. By default the builder looks for ‘main.lua’, and runs it. It is a required file and it kicks off the run-time of your project.

The lua file format shown here is my own creation. I use it for the main.lua file and then within any ‘classes’ which I create.

--------------------------------------
-- Imports
--------------------------------------
local TemplateClass = require ("com.rmc.projects.helloworldoop.TemplateClass");
--------------------------------------
-- Metadata
--------------------------------------
--------------------------------------
-- Main Entry Point
--------------------------------------
display.setStatusBar( display.HiddenStatusBar )
--CLEAR OUTPUT
print ("");
print ("");
print ("  -------------------  ");
print ("  -- HelloWorldOOP --  ");
print ("  -------------------  ");
print ("");
--CREATE
local templateClass = TemplateClass:TemplateClass();
print ("    samplePublicVar    : "..templateClass.samplePublicVar);
--TEST MEMBERS
local samplePublicMethod_str = templateClass:samplePublicMethod();
print ("    samplePublicMethod_str           : " .. samplePublicMethod_str);

1. Imports

There are no true ‘imports’ in Lua, nor in Corona. The ‘require’ statement fetches a separate lua file and includes it in the current lua file. In my usage this essentially ‘imports’ the custom ‘class’ of ‘TemplateClass’.

2. Metadata

While not shown here in main.lua, within some classes there are ‘module’ statements (and others?) that help Corona/Lua know how to treat the current file. I call this ‘metadata’.

--------------------------------------
-- Imports
--------------------------------------
--------------------------------------
-- Metadata
--------------------------------------
module (..., package.seeall)
--------------------------------------
-- Class Methods
--------------------------------------
-- PUBLIC STATIC
--[[
	This method is designed to...
--]]
--------------------------------------
-- Class Properties
--------------------------------------
-- PUBLIC STATIC
--[[
	This property is designed to...
--]]
--------------------------------------
-- Class
--------------------------------------
--[[
	This class is designed to...
--]]
function TemplateClass()
	--------------------------------------
	-- Properties
	--------------------------------------
	-- INSTANCE
	--[[
		This is a self-reference required by OOP structure
	--]]
	local me = {}
	-- PUBLIC
	--[[
		This property is designed to...
	--]]
	me.samplePublicVar = "samplePublicVar";
	-- PRIVATE
	--[[
		This property is designed to...
	--]]
	local _samplePrivateVar = "samplePrivateVar";
	--------------------------------------
	-- Constructor
	--------------------------------------
	--[[
		This is the constructor...
	--]]
	function me:constructor()
		--TRACE
		print ("TemplateClass:constructor()");
		--METHODS
		me:initialize();
		--RETURN
		return me;
	end
	--------------------------------------
	-- Methods
	--------------------------------------
	-- PUBLIC
	--[[
		This is the initialize.
	--]]
	function me:initialize()
		--TRACE
		print ("TemplateClass:initialize()");
		--DRAW
	end
	--[[
		This method is designed to...
	--]]
	function me:samplePublicMethod()
		--Test Private -- It Works!
		local _samplePrivateMethod_str = _samplePrivateMethod();
		print ("	_samplePrivateMethod_str   : " .. _samplePrivateMethod_str);
		return "samplePublicMethod";
	end
	-- PRIVATE
	--[[
		This method is designed to...
	--]]
	function _samplePrivateMethod()
		return "_samplePrivateMethod & ".._samplePrivateVar;
	end
	--------------------------------------
	-- Events
	--------------------------------------
	-- PRIVATE
	--[[
		This event handler is designed to...
	--]]
	function _onSampleEvent()
		return "_onSampleEvent";
	end
	-- RETURN INSTANCE VIA CONSTRUCTOR
	return me:constructor();
end

1. Class Definition

In my solution I place the ‘TemplateClass’ class in its own ‘TemplateClass.lua’ file and treat it like a Lua ‘module’. You can see in ‘main.lua’ how I import and create an instance of ‘TemplateClass’.

2. Static vs Instance Members

The instance members in this demo work great. I had static methods and static vars working too, but broke them somehow. I have removed them from this demo. I’m confident is possible.

3. Publicity / Privacy

The instance members in the demo feature full, working publicity and privacy. Nice.

4. Inheritance

I have not included inheritance in this demo, but it is possible. I’m working on a simple game that I will post soon. I have 3 generations of inheritance going on and it works FAIRLY well. For my onscreen objects I extend using ‘display.newGroup()’ as a base. It is a bit ugly how to override methods (See the Ludicroussoftware.com link above), but it works. I’ll post that in the future.

The Output

Copyright (C) 2009-2011  A n s c a ,  I n c .
Version: 2.0.0
Build: 2011.704
The file sandbox for this project is located at the following folder:
(/Users/srivello/Library/Application Support/Corona Simulator/HelloWorldOOP-27E895459A9154336232E091AB34F950)
-------------------
-- HelloWorldOOP --
-------------------
TemplateClass:constructor()
TemplateClass:initialize()
samplePublicVar          : samplePublicVar
_samplePrivateMethod_str : _samplePrivateMethod & samplePrivateVar
samplePublicMethod_str   : samplePublicMethod

1. Output Tool

By default the output comes through your Terminal (on mac). There is setup to get the output to come through Lua Development Tools (or other Eclipse based editor with the Lua Plugin). Once you build once, you leave the terminal and emulator open and just edit and save your code as you like. With each save, the simulator AUTOMATICALLY reruns the app and the terminal shows the output. The ‘build time’ is 100 Milliseconds or so. The speedy iterative development is great.

2. The Output

You can see in the output example above, the first few lines are outputted by Corona itself, then your custom

Conclusion

I created this demo as part of my evaluation of various mobile programming languages (Lua) and development environments (Corona SDK and Lua Development Tools). Coming from a (objectively speaking) really really spoiled development environment of Flash game development, I have the same basic gripes with Corona as I do with HTML5 gaming. The language (lua) is not fit for OOP. It is not intended to do so. Lua and Corona are indeed LIGHTNING FAST both at compile-time and at run-time. That is fantastic and cannot be under-stated.

The Corona SDK community is growing and offering some add-ons;

  • Lime – Tilebased gaming
  • PubNub – Multiplayer Gaming API
  • More community projects…

And now a few tangents…

Do I Need OOP?

No. But for me an implied architecture (implied within the built-in language features) of OOP or component-based development greatly speeds up development for me. I’m able to get more feedback from the IDE and reuse code more effectively. Many developers prefer procedural programming. I’m not sure why. If you have an opinion please post below. We will see TONS more gaming built upon the horrible limitations of JavaScript. If you love JavaScript, that is great. For me its not the right tool for game development.

Some OOP Solutions for Corona;

  • My TemplateClass solution shown in this post. It is not a complete solution, but it shows Lua language-features to mimic OOP.
  • LCS (Lua Class System) – I tested it. Works!
  • Classes.lua – I haven’t tested it yet.
  • OWL (Objects With Lua) – Nice name! I haven’t tested it yet. Here’s a blog about it.
  • CooL (Corona Object-Oriented Lua)- I haven’t tested it yet.

Upon a quick look, each appears to be valuable. Not sure which is the most full featured yet. In the future I may create a demo of each for comparison’s sake and blog about it.

Do I need a strong IDE?

Yes. I’m dumbfounded by developers who defend using text-edit as their tool of choice. Sure there is an warm-fuzzy feeling about being so ‘raw’. But an honest appraisal of your productivity will trump that if you are a serious contributor to your industry. Spend a few hundred dollars, spend a few thousand dollars on performant hardware and legally-licensed software designed for your productivity. Be a professional.

Game Development Environment Utopia

In my research in gaming technologies (Many, many HTML5 frameworks, Flash Platform, Unity3D, iOS, Android, Cross-platform iOS/Android), I am evolving an idea for the ideal game development setup. This list will probably change over time. The dream is a setup that works for small game projects and can scale up to large team projects.

  • Fast Code-Test-Code Cycles – Under 1 second allows for optimal iterative development
  • Fast Run-Time Performance – Stable 30 frames per second or greater across target devices
  • Great IDE – Project creation, project compilation, project debugging (breakpoints, stack/heap introspection), intellisense on built-in and custom libraries, etc..
  • Strong Typed Language – Implicit intent in your design, IDE-feedback/errors/auto-fixes, generics, deep refactoring, etc…
  • Scalable Graphics Pipeline – To facilitate multi-screen development. Vector source with run-time conversion to raster seems to be the best setup yet for 2D. Streaming textures is ideal for 3D.
  • Implied Architecture – OOP (ex. Java) and/or component based (ex. Unity3D)

Stay Tuned

  • I have created a complete game using Corona. A tutorial, HD Screencast Video, and full source code are coming soon.

Questions for the Readers

  • Do you a better OOP setup? Fork my code and push a solution. Great!
  • Know how to setup LDT to show debug output and breakpoints? Post a comment below!
  • Can you setup LDT to show intellisense (auto complete) for the Corona SDK classes? Post a comment below!

Next Steps

  • Hello World – Download the full source code*
  • Hello World OOP – Download the full source code*
  • Hello World OOP – Watch the HD Screencast Video Tutorial*
  • Checkout More Tutorials on LearningCorona.com (Fantastic!) and DesignerSandbox.com

*See ‘Member Resources’ below.

Member Resources

'Free Member'-Only Content

You must be a 'Free Member' to see this content. With your access you will enjoy members-only content like this, HD video tutorials, and access to complete source code.

Ready To Join?
  • Sign up for 'Free Member' level now. Its free!
  • Sign up for 'Paid Member' level to enjoy much, much more! (Invite Only)
Already A Free Member?
  • Log in and enjoy!

4 Responses to Corona SDK for Mobile Development

  1. Benjamin Cabé says:
    June 28, 2012 at 2:44 pm

    This a really neat tutorial!

    If you want to setup the debugger, you should use the small tutorial available on YouTube.

    Regarding the “intellisense”, I’ll try to update you soon with some information to set this up! :)

    Reply
  2. NiceWoong says:
    July 15, 2012 at 10:20 am

    hey motherfucker.
    where is the Intelisense? I can’t find

    Stop sounds disgusting, and just sending IDE to the my e-mail.
    sucking motherfucker.

    Reply
  3. NiceWoong says:
    July 15, 2012 at 10:22 am

    oh i missed sorry
    bad hacker cracked my ID. so sorry

    Reply
  4. Alex says:
    October 18, 2012 at 6:32 am

    Hi,

    Is it possible to have the Lua Development Tools for Eclipse do any kind of code-completion for CoronaSDK? So far my IDE doesn’t seem to understand any of the implicit Corona objects.

    Thanks,

    Alex

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Free Member Login

You are not currently logged in.






» Register
» Lost your Password?

Support Our Sponsors

Category

  • Industry News
  • Standards & Best Practices
  • Full Tutorials
  • RMC News
  • Events

Tag

3D AIR API AS3 AS3.5 Business Debugging Experimental Flash Flex Games HTML5 Java Loom Mobile Optimization Project Planning PushButtonEngine Robotlegs Smash WordPress WordPress Plugin

Brazilean Developers

  • Abendita.com
  • dclick.com.br
  • dm9.com.br
  • Fellyph Cintra
  • IgorCosta.org
  • MonadaSolucoes.com.br
  • PossibleWorldwide.com.br
  • Unit9.com

Developers

  • Adobe Blogs
  • Ben Forta
  • Colin Moock
  • Enrique Duvos
  • Flash Mobile Blog
  • Jess Freeman
  • Kevin Hoyt
  • Lee Brimelow
  • Paul Trani
  • Quasimondo
  • Renaun Erickson
  • Ryan Stewart

Free Assets

  • Free Sounds
  • HasGrafics

HTML5 Games

  • Closure JS Library
  • Eloquent JS Manual
  • Game Framework – CraftyJS
  • Game Framework – EaselJS

Italian Developers

  • alchimedia.com
  • corlan.org/
  • creativesource.it
  • dimix.it
  • fabiobiondi.com
  • gnstudio.com
  • Interpreting-tech.com/bemobile/
  • leonardorisuleo.info
  • lucamascaro.info
  • mart3.org
  • mxml.it
  • nxn.it
  • pirosoft.it
  • Preload.it
  • sonnati.wordpress.com/
  • webgriffe.com

Products

  • Adobe.com
  • Amazon Kindle E-Reader
  • ElectroServer
  • F*CSS
  • Flash Development Toolkit (FDT)
  • O'Reilly PureMVC Book
  • Samsung Galaxy Tablet
  • Unity3D

RMC

  • RMC Consulting

Spanish Developers

  • Flash Adictos
  • HTML Cinqo
  • Tutoriales Flash

Tutorial

  • Active Tuts
  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Unity3D Tutorials

Unity3D Games

  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Matt Eley's Blog
  • Unity3D
  • Unity3D Tools
  • Unity3D Tutorials

I Am Great!

   

Latest Portfolio

  • Live Media Steaming ApplicationMay 20, 2013, 5:06 am
  • Museum Kiosk Touch ScreenNovember 15, 2012, 9:00 pm
  • Happy Birthday Mobile AppMarch 14, 2012, 5:55 pm
  • Official Robotlegs MVCS DiagramFebruary 24, 2012, 1:36 am

Latest News

  • Intro to Loom Game EngineMay 19, 2013, 6:48 am
  • Cross Platform Mobile: Free TalkDecember 21, 2012, 7:14 am
  • Cross Platform Mobile: Premium TrainingDecember 20, 2012, 7:41 am
  • Must-Have Non-Functional RequirementsDecember 14, 2012, 4:05 am

Latest Tweets (@srivello)

  • Very inspired by the #XBoxOne. The presentation's focus on non-game features is both bold and a bit scary as a gamer.
  • 3 hours into my Centipede clone using #2DToolkit for #Unity3D http://t.co/5yWsMQvHEU
  • @pixelplacement I've seen 'iTween Parameter Code Hinting' but anyone done a completely strong-typed (no hash) version of iTween?
  • @pixelplacement Great work on iTween!!! Thanks.

© Copyright 2006 - 2013 - Rivello Multimedia Consulting - Flash / HTML5 / Unity3D Game And App Development With Tutorials