Options to create mobile apps

There are plenty of fish in the sea, that's true when your heart is broken, otherwise the fish that you have is the best fish. In terms of development, there are no heart breaks but what the clients ask for. Generally they want something that is quick, standard and will cost them less. Quick because they want to get it out of the door as fast as they can, Standard as they might want to further it in-house or get another developer, so if the framework is Non-Standard, finding support would be difficult and lastly, Cost, even for you as a developer and for the client, you want a tool that does everything that you want but does not cost you an Arm and a leg and a couple of other organs that you can donate.

Adobe Photoshop is the king of all graphical tools, but everytime they have a new release, it is *impossible* to upgrade, specially given the costs and specially if you are not a Graphic Artist. However, there are tools like Pixelmator that fill the gap and do a good job, going even further down in price, you can also get Gimp.

Developers making apps for the mobile devices are generally caught up with using Java for Android and Objective-C for iOS. Then if they want something cross-platform, it is just a nightmare as the code is not portable. So this gap bred a whole new breed of frameworks that allowed developers to work with a common language that would generate binaries for multiple platforms. Frameworks like Cocos-2D, Sparrows, etc are still objective-C based and do not compile for Androids. The frameworks that are cross platform are generally Lua based and include CoronaSDK, Gideros form the top performing ones. Without getting into the discussion of is Microsoft better than Apple, let's say both do a good job, and both have their shortcomings/limitations.

Lua has become so popular and easy to use that Corey had released WAX, a framework that sits as a wrapper around objective-C and makes all methods and properties available via Lua scripting. LuaCocoa from Eric Wing, a brilliant engineer now working for Ansca (CoronaSDK) could have the potential, but he is bringing in great enhancements to the CoroanSDK framework, Steffen has Kobold2D, a Lua wrapper on cocos2D. Simeon released Codify, now named Codea on the iPad that uses Lua and allows creating apps on the device itself. There is another one called LÖVE, a lua based desktop framwork that generates apps for the Desktops, be it Mac OS X, Windows or Linux.

We have has many tutorials on using CoronaSDK, today we shall look at Gideros and how it works and maybe a few parallels with CoroanSDK.

First steps

The first major difference that you will notice with Gideros over coronaSDK, is that it starts with an IDE. That holds all the project related files in one place ans saves them all as a project like you would in Visual Studio or xCode or Eclipse.

Like all C code has int main() as the entry point, the entry point for Lua based code is the main.lua file.


Hello World

We are not writing a hello world example, but the basics to understand how things work, we need to understand that in Gideros everything is an Act, in the sense, "All the world's a stage" to have anything displayed on screen, you have to put them on stage.

Given that Gideros is modeled on Flash, there is a very strong similarity and a lot of Flash developers will immediately feel at home. Not being from a Flash background, I felt like a guest than at home. However it is easy to get used to.

Example App

We shall look at the Bird animation sample that comes with Gideros.

local bg = Bitmap.new(TextureRegion.new(Texture.new("sky_world.png")))
    stage:addChild(bg)

These two lines place a background on the screen, let us see what those two lines do

local bg = Bitmap.new(TextureRegion.new(Texture.new("sky_world.png")))

creates a new Texture called "sky_world.png" --> Texture.new("sky_world.png")
This texture is passed as a parameter to creating a new TextureRegion from that
This TextureRegion is then passed to create a new Bitmap and the handle to this bitmap is assigned to bg

The next line adds this background held in bg to the stage.

If this is a mouthful, then the beauty of functions is that you can encapsulate a lot of redundant code, so I would just have a function called

local function newImage(filename)
   
   local theImg = Bitmap.new(TextureRegion.new(Texture.new(filename)))
   stage:addChild(theImg)
   return theImg

  end


Now all I need to do is use it as

local bg = newImage("sky_world.png")

makes it easier and readable, I think the reason that the makers of Gideros did not abstract it to that level is that they respected that the developers *might* want a little more granularity on the lower levels of the system. so rather than abstract it off completely they have offered the choice here.

The code continues to define how the bird animation is achieved, the birds are a series of sprites. that have 3 frames to animate the flapping of wings. Each class is self contained/defined with its own set of actions like any true OO class should be, and in this case it also has delegate methods.

The bird is a subclass of the sprite class and defined as
Bird = gideros.class(Sprite)

and then the two delegate methods are defined that *could be invoked if they exist.

function Bird:init(frameList)
 end

 function Bird:onEnterFrame()
 end

I have a few doubts on should the code be using Global declarations? The same can be managed in better ways, this allows the main.lua to access the variable Bird by using

local bird1 = Bird.new(frames1)
 local bird2 = Bird.new(frames1)

  stage:addChild(bird1)
  stage:addChild(bird2)


I recollect that all the lua files are executed on startup so all of the code becomes available to the modules, not sure if that is such a good thing when there are several resource intensive like why should all the levels of my game be loaded simultaneously?
I would personally change a few things in this code to make it local friendly as

In the main.lua
local Bird = require("bird")

  local bird1 = Bird.new(frames1)
  local bird2 = Bird.new(frames2)


and the code in bird.lua to reflect as

local theBirdClass = gideros.class(Sprite)

    local function init(self, frame)
    end

    local function onEnterFrame(self)
    end

   return theBirdClass

I need to run this through a profiler to see if there is any improvement over the earlier global using code.

The best part of Lua and functions is that you can change the look and feel of the language as you wish.

So, I can also have a simple function in main.lua defines as

local function newBirdSprite(theFrames)
    local theSprite = Bird.new(theFrames)
    stage:addChild(theSprite)
    return theSprite
  end


so with these changes, the ample code that was

local bg = Bitmap.new(TextureRegion.new(Texture.new("sky_world.png")))
stage:addChild(bg)

local Bird = require("Bird")

local frames1 = {
 "bird_black_01.png",
 "bird_black_02.png",
 "bird_black_03.png"}

local frames2 = {
 "bird_white_01.png",
 "bird_white_02.png",
 "bird_white_03.png"}

local bird1 = Bird.new(frames1)
local bird2 = Bird.new(frames1)
local bird3 = Bird.new(frames2)
local bird4 = Bird.new(frames2)

stage:addChild(bird1)
stage:addChild(bird2)
stage:addChild(bird3)
stage:addChild(bird4)

would now look like
local function newImage(filename)
   
   local theImg = Bitmap.new(TextureRegion.new(Texture.new(filename)))
   stage:addChild(theImg)
   return theImg

  end

  local function newBirdSprite(theFrames)
    local theSprite = Bird.new(theFrames)
    stage:addChild(theSprite)
    return theSprite
  end

  local Bird = require("Bird")

  local frames1 = {
 "bird_black_01.png",
 "bird_black_02.png",
 "bird_black_03.png"}

  local frames2 = {
 "bird_white_01.png",
 "bird_white_02.png",
 "bird_white_03.png"}


  local bg = newImage("sky_world.png)

  local bird1 = newBirdSprite(frames1)
  local bird2 = newBirdSprite(frames1)
  local bird3 = newBirdSprite(frames2)
  local bird4 = newBirdSprite(frames2)

and the bird.lua file that looked like

Bird = gideros.class(Sprite)

function Bird:init(frameList)
  --snipped code
end

function Bird:onEnterFrame()
  --snipped code
end


would now look like

local theBird = gideros.class(Sprite)

 local function init(self,frameList)
  --snipped code
 end

 local function onEnterFrame(self)
  --snipped code
 end

 theBird.init = init
 theBird.onEnterFrame = onEnterFrame

 return theBird


The idea here is to demonstrate the ease of use and adaptability of the platform. It is quite powerful and can be wrapped in functions to make it easier to use.

hope you can try and make it work for you. We shall look at other samples / frameworks in our other articles/posts.

Comments

  1. Thanks OzApps for this very interesting article. Would you say the learning curve is the same as for Corona, or easy if one already knows Corona?

    ReplyDelete
  2. most of the frameworks, Corona, Gideros, Sparrow work on the basic principals of ActionScript. So they are more or less similar in that way, then Gideros and Corona are both Lua based.

    The learning curve issues that any developer (experienced or new) will face are
    1. Understanding Lua and how it works
    2. Understanding the API for any framework
    3. Understanding the limitations of bugs in the framework.

    So if a developer is well versed in one framework, it should not be difficult to move, but there will be the transition of understanding the API's available in the new framework.

    ReplyDelete
  3. Thanks Oz. Just read your Free Beer post, very interesting and I have some of the same concerns. After starting with xCode I'm a bit regretful that I didn't just continue and get through the learning curve (got pretty far into it). Given the fact that after investing the time in Corona and Lua I'm feeling a bit dependent. Do you have any experience with Gideros and have gathered a list of pros and cons for that?

    Thanks for all your work and posts!

    ReplyDelete
  4. Keep a look out, I shall be posting a comprehensive comparison of CoronaSDK against other frameworks soon. Just a bit too busy with some deadlines and projects.

    ReplyDelete
  5. Thanks again, I will.

    fava

    ReplyDelete

Post a Comment

Popular Posts