基本全都在Cocos2dConstants.lua文件里,感觉比C++版本的使用起来要更方便直观,摘抄一些常用的列出来:

frameworks/cocos2d-x/cocos/scripting/lua-bindings/script/Cocos2dConstants.lua

cc.PLATFORM_OS_WINDOWS = 0
cc.PLATFORM_OS_LINUX   = 1
cc.PLATFORM_OS_MAC     = 2
cc.PLATFORM_OS_ANDROID = 3
cc.PLATFORM_OS_IPHONE  = 4
cc.PLATFORM_OS_IPAD    = 5
cc.PLATFORM_OS_BLACKBERRY = 6
cc.PLATFORM_OS_NACL    = 7
cc.PLATFORM_OS_EMSCRIPTEN = 8
cc.PLATFORM_OS_TIZEN   = 9

cc.LANGUAGE_ENGLISH    = 0
cc.LANGUAGE_CHINESE    = 1
cc.LANGUAGE_FRENCH     = 2
cc.LANGUAGE_ITALIAN    = 3
cc.LANGUAGE_GERMAN     = 4
cc.LANGUAGE_SPANISH    = 5
cc.LANGUAGE_RUSSIAN    = 6
cc.LANGUAGE_KOREAN     = 7
cc.LANGUAGE_JAPANESE   = 8
cc.LANGUAGE_HUNGARIAN  = 9
cc.LANGUAGE_PORTUGUESE = 10
cc.LANGUAGE_ARABIC     = 11


cc.EVENT_UNKNOWN               = 0
cc.EVENT_TOUCH_ONE_BY_ONE      = 1
cc.EVENT_TOUCH_ALL_AT_ONCE     = 2
cc.EVENT_KEYBOARD              = 3
cc.EVENT_MOUSE                 = 4
cc.EVENT_ACCELERATION          = 5
cc.EVENT_CUSTOM                = 6

在frameworks/cocos2d-x/cocos/scripting/lua-bindings/script/目录下还有不少其他的.lua文件都定义了不错的API,值得看一遍,做到心中有数,比如在cocos2d.lua中定义的快速生成点对象的方法cc.p()等相关方法:

--Point
function cc.p(_x,_y)
    if nil == _y then
         return { x = _x.x, y = _x.y }
    else
         return { x = _x, y = _y }
    end
end

function cc.pAdd(pt1,pt2)
    return {x = pt1.x + pt2.x , y = pt1.y + pt2.y }
end

再比如json.lua中的encodedecode方法、AudioEngine.lua中定义的可以直接使用的全局变量AudioEngine,都是使用Lua带来的福利,这些.lua文件都值得看一遍,了解多出来的这些可以方便使用的函数,提高代码效率。


洪亮
697 声望65 粉丝

引用和评论

0 条评论