segunda-feira, 9 de maio de 2011

Loader Class


Hello folks,

I have finished the version 1.0 of my new Loader Class. This class is different from Director, it's for expert users and transforms your application in a object oriented development. I will explain now some steps to use it properly.

1 - Download the source code:

https://bitbucket.org/ricardorauber/corona/downloads/loader_by_ricardo_rauber_1_0.zip

2 - Take a look on the little samples in the main.lua file.

3 - Change the DEBUG variable to true:

loader.debug = true

4 - Creating objects.

Ok, let's talk more about this. In Lua, you can use tables as objects, and that's exactly what we will do. Let's go through the car.lua file.


4.1 - Every file (or class) must be a module on a new file, so the very first line should be:

module(..., package.seeall)

4.2 - Like Director Class, Loader Class search for a new() function and expect a display group as a return.

4.3 - You can pass a table with parameters to your class, Loader will send it through the new( params ) function of your class.

local car1 = loader.newGroup( "car" , {image=carImg, name="Ford",  width=carWidth, height=carHeight} )

4.4 - Inside of the new() function, you have to create a display group and assign to it all your variables and functions. In Object Oriented Programming, we call them attributes and methods.

-- Attributes
tabCar.name = "default"

-- Methods
function tabCar.setName ( pName )
if type( pName ) == "string" then
tabCar.name = pName
end
end

4.5 - Finally, you should create a constructor function or just some steps to initiate your object.

function tabCar.constructor ( par )
-- Some code here
end
tabCar.constructor( params )

-------------------------------------------------------------

I know that's difficult to understand for most of developers but I'm planning to make a video about it. Also, I already sent a game called DevMine to Apple Store that was all developed with Loader Class. The source code will be available via in-app purchase for US$ 0.99.

Now talking about Director Class, it will be upgraded on version 1.3 with some new features that I made with Loader Class like the debug and error messaging. Also, there's a pop up to show scenes without cleanning the old one.

Thanks!

-------------------------------------------------------------

Um comentário:

  1. Great Info.

    Checkout this Tutorial on OOP With The Corona SDK
    http://bit.ly/KLYKZv

    ResponderExcluir