Category Archives: Corona SDK

Simple loading sprite animation

Ok, here is a very simple tutorial on creating animation using sprite image in coronalab. Most game developer/designer have no difficulty in understanding what is a sprite. Sprite is basically a ground of images composed into 1 big image, where each pieces represent a frame in timeline. By playing these frame one by one very fast, we create an illusion of animation. Yes, tat’s the same concept how Disney did it for their early day cartoon show. So, now, we have a sprite image ready here: sprite The image filename is sprite.jpg, with size in 648 (width) x 214 (height) pixel. There are total 4 frame, just a simple animation. Each frame size is 162 (width) x 214 (height) pixel. Ok, now the coding part. In corona, we first need to initialize the image sheet data: we take in 5 parameters when creating sheetData variable:
  1. width: width of the single frame 648/4 = 162 pixel
  2. height: always 214 pixel as our sprite image is a horizontally long image. There are more complicated cases where your sprite might be more than 1 row.
  3. numFrames: only 4 here as you can see
  4. sheetContentWidth: your sheet image size in width, is 648 pixel
  5. sheetContentHeight: same as above, but in height, is 214 pixel
once you get these value set correctly, you create the imageSheet variable by passing in the image file path and name, then this sheetData too as parameters. Next, you need to create another variable called sequenceData. This will tell corona how to play your sprite. Our animation here is very straightforward, just keep looping it from 1st frame to last frame. Then, we create the loadingSprite object using imageSheet and sequenceData as parameters. we add in these code to position it at the center of screen: Last but not least, play it using this command: Source code for this tutorial is available at gitlab repository (public). For more advance and complete tutorial, please refer to Coronalab Tutorial here.

Gradient changes due to migration to Graphic 2.0

Previously, prior to Dec 2013, we use gradient in corona sdk as below: However, latest update have deprecated the graphics.newGradient. More info can be found here at: http://docs.coronalabs.com/guide/graphics/migration_g20.html#TOC Your Corona SDK will give you the following warning when you try to run the old code. gradient So, use this for now:    

Introduction to Corona SDK

I have been developing mobile apps using many different tools like phonegap, html5 (mobile web), objective-c and android SDK (native code). Each of them have own pro & cons and I choose accordingly to the nature of the project. However, I still wish for a perfect tool where I can write once and automatically have it compile to multiple platform without scarifying performance, development cost and speed, etc. Corona SDK is very close to what I asking for. It allows you to write once and compile to multiple platforms (IOS, Android, Kindle…) and is best for casual 2D gaming and informative type of application. Simple & Faster It used LUA scripting language, which have low learning curve. For example, to display an image in Android: On the other hands, for Corona is as simple as 1 line code: Now, the cons part of Corona SDK:
  • Need to wait for Corona for new features
  • Need to wait for Corona for new platform (very very slow, after 4 years window phone is release and there are still no support for it)
  • Free version can’t integrate with native code
  • Some advance features required plugins
  • Some of the premium features like analytics are not available on Free version
For business App: Like many others cross platform development tool, Corona SDK too lack of advance UI form component such as calendar selector, color picker and etc. You can however implement these on your own. IOS vs Android Overall, as majority mobile users is either in the IOS or Android camp, Corona is working fine. Bear in mind, you still need a mac to compile the same code to ipa file for ios release; and jdk must be installed to compile to apk for android release. As corona was initially developed to target IOS where screen size is fixed, then only added android support, it used a mechanism called screen scaling to tackler different screen size resolution and ratio issue. You can either choose to have a padding (like TV), or zoom evenly (with risk that some content might get cropped), or stretch to screen (where your app could run off ratio). The Simulator The corona simulator is fast and responsive, allowing rapid prototyping and trial-n-error oriented development; with a weak point such as webview are not supported. You will need a real device to test this function. As Hybrid App Yes, when I mentioned webview, you probably looking forward to embed HTML into corona app to make use of the best of both world. Good news is, Corona do allow HTML and its resources (Javascript, css, images…) to be embedded as in app resource; or, loading an online URL. So, why wait now? start try it out at http://www.coronalabs.com Lots of tutorial and comprehensive documentation can be found there. I will write more about Corona tutorial in near future too.