Send custom events with EventDispatcher for Corona SDK / Lua

In Corona SDK, event listeners can only be added to the global Runtime object or to display objects. In order to broadcast messages to event listeners, the event dispatcher is limited to either one or the other. This limitation places messaging in the two scopes instead of between objects that are supposed to be talking to each other. I’ve seen many examples with display objects that are created solely for the purpose of dispatching events. This just doesn’t feel right to me; so I’m releasing my EventDispatcher, perhaps other developers may find it useful too.

Those who came from the good old Flash 5 days may remember FLEM (FLash Event Model). It was the first listener event model for Flash and ActionScript, and was created by Branden Hall and further developed and maintained by me. I’ve adapted the basic event model mechanism found in ActionScript 2/3 to Lua. This EventDispatcher has a similar interface as the listener model in Corona SDK, with some extra features thrown in (such as optional extra parameters when dispatching events, and returning status).

EventDispatcher provides custom event broadcaster/listener mechanism to regular Lua objects, it works as regular Lua 5.1 / 5.2 code, in Corona SDK, and likely other Lua-based frameworks.

Basic usage:

Sample code below demonstrates how it can be used:

Here is the output from the code:

iPad is turned off by Artist2 (table)
Artist2 is resting
Rested 1
Cowboy1 is drawing a gun
Cowboy2 is drawing a gun
Artist1 is drawing a picture
iPad is turned on by Artist2 (function)
Artist2 is drawing on the iPad
Removed
iPad is turned off by Artist2 (table)
Artist2 is resting
Artist1 is resting
iPad is turned off by Artist1 (table)
Rested 2
Cowboy2 is drawing a gun and shooting a bandit
iPad is turned on by Artist2 (function)
Artist2 is drawing a bandit on the iPad
Mayor collected 42 pieces of gold from Dave

And here is the EventDispatcher module:

EventDispatcher provides a broadcaster/listener event mechanism to regular Lua objects. Corona developers can write cleaner object-oriented messaging code that doesn’t rely on display objects or send messages from the global Runtime.

For the latest code, check out EventDispatcher at github.

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

Lua table remove by key

Lua has a table.remove() function that deletes an element from a table at the specified position, or the last element by default. However, it doesn’t work when the table is an associative array (e.g. {name=”swfoo”, domain=”swfoo.com”} ).

Below is a simple function that deletes a key-value pair from a table. One important feature to note is that instead of modifying the original table, it returns a new table.

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

A mighty PNG

This innocent-looking PNG image makes a huge difference to iOS apps if you need to target retina display devices. At 640×1136 and named “Default-568h@2x.png”, this default launch image tells the app to run in full retina resolution on devices such as iPhone 5. What’s different with this image is the tiny file size of only 184 bytes. You’re welcome to grab it and use it.

Default-568h@2x.png

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

Develop and publish mobile apps for free

Corona Labs announced a completely free version of Corona SDK for developing and publishing mobile apps and games. This is great news for anyone who wants to create apps without paying a single cent. Students, indie developers and hobbyists would benefit most from this announcement.

What’s the catch? Well, there really isn’t one, except the new Starter version does everything the Pro version did, minus these three features: In-app purchases, analytics, and access to daily builds. Corona Labs doesn’t even require their splash screen to be displayed like some other “free” SDKs. A developer can use the Starter version to make apps and earn money by either charging up-front, using ads, or other means.

You’re probably thinking why would Corona Labs make this move. The reason is simple: Attract more developers to their platform (SDK and Corona Cloud). If developers feel the need for the three features and upcoming “pro” features, they would upgrade to the Pro version. Some pro features Corona Labs mentioned they’re working on include: new graphic features using OpenGL 2.0, plugins, device access through native code (maybe, but not full-blown like the Enterprise edition).

For existing developers with Indie subscription, they’re now automatically upgraded to the Pro version. For Pro subscribers, they get two extra months of subscription. For Enterprise subscribers, there’s no change.

There is, however, a price increase for the Pro version starting May 1st, 2013 from $349 to $599 per year. For pro subscribers, as long as their subscriptions are not expired by April 30th, they can upgrade twice at the old price of $349. For anyone who wants to take advantage of the lower price (for the next two years), subscribe by April 30th! More info at their pricing page and the conversation with their COO.

As a side note, Corona Cloud is an exciting server solution for any developer (not just Corona developers) who needs features such as User accounts & authentication, Leaderboards & Achievements, Multiplayer, Push Notifications, Social Connect, Cloud Sync, Chat, News, and Analytics. This simplifies greatly dealing with the server from a developer’s point-of-view.

For those who are interested, Walter Luh (CEO of Corona Labs), will be coming to FITC Toronto this month. His presentation is Building Native Apps: A Digital Canvas for Coders and Designers.

Off to making apps that people love…

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

Painting on iPad (with Procreate and Sensu brush)

Tablets are becoming productive tools and not just for media consumption. Back in the days of the Amiga, I had a Wacom tablet; it worked well but the drawing programs were quite primitive. Today, with tablets and many decent drawing and painting apps, artists can be creative wherever they go.

Procreate is an amazing painting app for the iPad, with features found in professional software, and costs only $4.99. This may seem expensive to some, considering many apps are free. However, this is probably the best $4.99 I’ve spent on apps. Today, version 1.7 is released, and it adds at least two new features that I was hoping for: full-screen mode and 4K resolution. Together with the Sensu brush, even my parents feel comfortable painting on the iPad.Procreate

The Sensu brush looks like a traditional artist brush, with special brush hair on one end that works with capacitive touch screens, and a rubber tip on the other as a regular stylus. It feels balanced, comfortable, and at the right length.

Sensu brush

Another similar but simpler app I like is Paper. It’s for drawing or writing notes, and is free. In the free version, there is only a single pen tool and a limited number of colors. With in-app purchases, additional tools and a color mixer can be added for about $9, which is a little high for a simple app like this. But then, it’s the simplicity that’s the beauty of this app. With Paper and the lighter iPad mini, I can see this combination as an everyday notepad for jotting down ideas and sketches.

Last but not least, the Pogo Connect is a much talked-about pressure sensitive Bluetooth stylus. Both Procreate and Paper support it. I have yet to try it as the cost ($80) is higher than the other pens, especially for casual drawing.

Using the iPad as a creative tool for artists is becoming a reality with these apps and styluses (styli). As we’re moving away from the PC era, tablets already fulfill the needs of most people. As a new media software developer, working on a computer with a real keyboard is still the only choice. I can’t wait to see what the next generation of software development tools will be like. And no, I don’t think Siri is the answer. :)

 

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

Screens 2011 = New FITC Mobile Conference

For those who follow this mobile development space, the FITC Mobile conference in Toronto should be familiar. This year, the event is renamed to SCREENS.

It’s two full days of presentations and one optional day of workshop, all focused on mobile development for various devices.

Topics covered include:

Android OS • App Success • BlackBerry Tablet OS • Corona SDK • Designing for Mobile • Mobile Marketing • Digital Home • Grand Central Dispatch and Blocks • iOS • jQuery Mobile • Managing Mobile Projects • Metro • Microsoft Stack • HCI • QNX • Thread Management • UI • UX • Windows Phone

Companies represented include:

Microsoft • Adobe • HP • Wavefront • Indusblue • QNX • Mobicartel • Ludicrous Software • Jam3 Media • Best Buy • WhereCloud Inc. • Almer/Blank • Transcontinental Interactive • Teehan + Lax • Canadian Film Center

And speakers include:

Adam Stanley • Alex Kennberg • Bob Burns • Brad Wing • Brady Gilchrist • Chuck Freedman • Darren Osadchuk • Erik Von Harten • Faisal Abid • Greg Carron • Hod Greeley • James Maynard • Jean-Luc David • Joshua Granick • Joshua Marinacci • Julian Dolce • Kevin Suttle • Marin Alejandro • Martin Dufort • Matt Fisher • Matt Rix • Matthew Patience • Mikko Haapoja • Paul Laberge • Pearl Chen • Peter Nitsch • R Blank • Renaun Erickson • Robert Burdick • Rogers • Ryan Creighton • Sam Mithani • Scott Janousek • Steve Mason • Ted Patrick • Timothy Quinn

November 14-15, 2011 at the Metro Toronto Convention Centre.

Thanks to the folks at FITC, here is a 10% off promo code: Quantumwave. The super early bird special ends on August 26, just 3 days away.

See you there!

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr

Screen scaling for different devices

In multi-device development, one of the issues to deal with is displaying the same content in different screen resolutions. Corona SDK offers a simple solution by specifying the scaling mode in the config.lua file. The scaling modes include: none, letterbox, zoomEven, zoomStretch. Sometimes it’s easier to understand by seeing the visual difference than reading the docs.

Below are the 4 modes displayed in four different devices (starting top-left clockwise: Galaxy Tab, iPad, iPhone & iPhone 4). The background photo is loaded at the Galaxy Tab screen resolution (1024×600).

To view the original full-size images, click on the images to view at Flickr (then choose Actions -> View all sizes), or use the links at the bottom of this post.

 

None

Screen Scaling None

 

 

Letterbox

Screen Scaling Letterbox

 

ZoomEven

Screen Scaling ZoomEven

 

ZoomStretch

Screen Scaling ZoomStretch

 

The source files used to create the display can be downloaded here. The four full size images are here: None, Letterbox, ZoomEven, ZoomStretch.

Hope this is useful.

 

Share this: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneShare on RedditPin on PinterestShare on Tumblr