Tải bản đầy đủ (.pdf) (23 trang)

ansca-corona-102.pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (492.5 KB, 23 trang )

TM
www.anscamobile.com
TM
www.anscamobile.com
What’s Corona
A simple, yet powerful framework allowing rapid
mobile cross platform application development.
TM
www.anscamobile.com
Corona 102
Functions &
EventListeners
TM
www.anscamobile.com
Corona framework based on Lua
TM
www.anscamobile.com
Corona Lua resources

/> /> />TM
www.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 code
reusing code becomes hard to break apart
debugging becomes a nightmare
no sense of where program starts
TM
www.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 code
easier to re-use code on other programs as well
easier to debug since you can narrow down where error occurs
a sense of where program starts
TM
www.anscamobile.com
Corona Functions:

First-class values.

Passed by value.

Stored in tables.

Returned from functions.

Global and local.

called from other ‘packages’
TM

www.anscamobile.com
Corona Function Definitions:
function name(args)
body
return [values]
end
Global Function
local function name(args)
body
return [values]
end
function local to file scope
f = function (args)
body
return [values]
end
Anonymous function
function ( ... )
body
return values]
end
(...) indicates variable args and {...} places them in a table where
they processed in standard way.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×