Ludicrous Software

Mobile and Flash Development

Scope in Corona

Scope in Lua can be a bit of a challenge if you’re used to how scope works in other languages, such as AS3. Rather than try to write the exhaustive, authoritative description of scope in Lua, I figured I’d do a quick overview to explain a few things that may not be obvious when you’re starting out, and also describe how I typically handle potential scoping issues.

hasEventListener() in Corona

One of the nice things about Corona if you’re a Flash developer is the similarity between Corona’s API and some Flash APIs. For example, the event listener, although different in some respects, are also quite similar, which makes learning Corona a lot easier. But sometimes, those differences mean you’re missing out on things that you “take for granted” in Flash. For example, Corona has no native hasEventListener function. But I needed one, so I wrote one.

Speed Up Device Builds in Image-heavy Apps

I’m currently working on an image-heavy Corona iPad application for a client. And when I say “image-heavy”, I mean extremely image-heavy. The app is about 150MB in size, and about 99.8% of that is PNG images, and most of those images are fullscreen (i.e. 1024 x 768) images. It takes about eight(!) minutes to build the app using the latest public release of the Corona SDK, and I wanted to find a way to speed that up.

Fixing the Corona Debugger in Snow Leopard

Last week somebody commented on my post about using the Corona debugger that they’re getting an error with one of the daily builds. I tested this out against the latest public build and I experienced the same thing. Here’s what I’m seeing:

dyld: Library not loaded: /usr/lib/libedit.3.dylib
  Referenced from: /Applications/CoronaSDK/debugger
    Reason: image not found
Trace/BPT trap

Build Missile Command With the Corona SDK

Last week I had the pleasure and the honour of being able to deliver both an introduction to Corona presentation and a full-day game development workshop at FITC Screens. The workshop attendees built (most of) a complete cross-platform Missile Command game using the Corona SDK; we ran out of time before we could implement everything you’ll find in the workbook, but we covered all of the basics. I’ve uploaded the materials I used in the workshop to GitHub, so feel free to check it out.

Performance of Local v. Table Functions

Short version: If you’re creating a Lua module with publicly accessible functions, just add the functions as properties of the table you’re returning, rather than as local functions with a table reference. Now for the long(er) version…

Update: added one more example for further context. It’s at the bottom of the post.

Using `do/end` for Disposable Code

This is a quick tip about how to take advantage of scope in Lua to keep memory consumption down. Typically, any application that you write is going to have some initialization code. By this, I mean code that is going to run once and only once. It may set up some initial values, do a bunch of calculations to configure your app for the specific device it’s on, and so on.

Corona Physics: Forced Horizontal/Vertical Bouncing

This recent article on the Ansca web site about solutions to common physics challenges is helpful, but as one commenter notes, the issue of objects “sticking” to walls isn’t easily solved by using the suggestions provided in the article. The commenter notes that the Corona Physics API doesn’t expose the collision properties required to properly handle these sticky (ha ha) situations. So here’s how you can hack around the problem when your walls are completely horizontal or vertical (situations where the collision is with non-horizontal/vertical objects are somewhat more complicated, and I’ll deal with those in a subsequent blog post).

Fastest Way to Remove All Event Listeners

Removing the event listeners that you’ve created is key to avoiding memory leaks in your Corona applications. Here’s a simple little function that will remove all of the event listeners attached to a particular object.