23
TM www.anscamobile.com

Ansca Corona 102

Embed Size (px)

DESCRIPTION

jkklkjlkjlkjlkjljlkjlkjkjnkjbkjb

Citation preview

  • TM

    www.anscamobile.com

  • TMwww.anscamobile.com

    Whats Corona

    A simple, yet powerful framework allowing rapid mobile cross platform application development.

  • TMwww.anscamobile.com

    Corona 102 Functions &

    EventListeners

  • TMwww.anscamobile.com

    Corona framework based on Lua

  • TMwww.anscamobile.com

    Corona Lua resources

    http://ww.lua.orghttp://www.lua.org/lua-l.htmlhttp://developer.anscamobile.com/http://en.wikipedia.org/wiki/Lua_

  • TMwww.anscamobile.com

    Corona Without functions

    local text = display.newText("hello",100,200,"Helvetica",24);textObj:setTextColor(r,g,b);

    Disadvantages:

    When program begins to get too big, difficult to manage codereusing code becomes hard to break apartdebugging becomes a nightmareno sense of where program starts

  • TMwww.anscamobile.com

    Corona With Functions:local function STextColor(textObj, r,g,b) textObj:setTextColor(r,g,b);end

    local function main()local text = display.newText("hello",100,200,"Helvetica",24);STxtColor(text,255,0,0);end

    main()

    Advantages:

    easier to manage codeeasier to re-use code on other programs as welleasier to debug since you can narrow down where error occursa sense of where program starts

  • TMwww.anscamobile.com

    Corona Functions:

    First-class values.Passed by value.Stored in tables.Returned from functions.Global and local.called from other packages

  • TMwww.anscamobile.com

    Corona Function Definitions:function name(args) body return [values]endGlobal Function

    local function name(args) body return [values]endfunction local to file scope

    f = function (args) body return [values]endAnonymous function

    function ( ... ) bodyreturn values]

    end(...) indicates variable args and {...} places them in a table where they processed in standard way.

  • TMwww.anscamobile.com

    Corona More function definitions:

    function obj:name(args) body return [values]endObject function getting extra args and self

  • TMwww.anscamobile.com

    Corona Calling functions:foo(args)simple call. returning zero or more values.

    t.f(args) calling function store in field f of table t

    local function f(mode, value) body

    endlocal function with two arguments

    r = f { value =3.14159, mode=auto}Calling a function with table, args can be passed by name.

    function f(t)body

    endarguments accessed as t.value, t.mode

  • TMwww.anscamobile.com

    Corona EventListeners:

    Coronas event listeners are part of the Corona framework and not part of the Luaprogramming language.

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Corona EventListeners:

    Event listeners allow Coronas display objectsand program scope to register for specific events to respond to.

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Corona EventListeners:

    To setup an event listener you must

    attach an addEventListener.register a function to listen to the event.Optional, remove the event listener after use.

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Corona EventListeners:

    There are two types of event listeners

    Runtime dispatched by the systemDisplay-object self-explanatory.

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Corona Runtime Event Listeners:

    local function onEnterFrame(event) print (event.name)end

    Runtime:addEventListener(enterFrame,onEnterFrame)

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Corona Display Object Event Listeners:

    local button = display.newImage(button.png,15,25);

    local function button:touch(event) print (event.name)end

    button:addEventListener(touch,button)

    http://developer.anscamobile.com/content/events-and-listeners

  • TMwww.anscamobile.com

    Listeners

    local listener = function(event)print( event.name, event.time )

    end

    Runtime:addEventListener("enterFrame", listener)

  • TMwww.anscamobile.com

    Event Types

    enterFrame system orientation accelerometer GPS heading touch timer ...

  • TMwww.anscamobile.com

    Touch + Multitouch

    x y xStart yStart phase id time

  • TMwww.anscamobile.com

    cicaza @ anscamobile dot com

    twitter.com/anscafacebook.com/ansca

    developer.anscamobile.com/forumshttp://developer.anscamobile.com/code/http://developer.anscamobile.com/resources/apis/

  • Corona SDKCode Less. Play More.