所有testcpp裏的widget示例都已實現,實現了一個GuiExample,其他的就留給大家去熟悉.其實無非就是講c代碼拷貝到lua裏然後修改一點...
http://pan.baidu.com/share/link?shareid=2377009888&uk=2956369506 代碼,pkg和示例的包
使用步驟:
1.解壓下載包
2.將extensions下的CocoGUILIB文件夾備份下,然後用解壓的CocoGUILIB覆蓋原文件夾
3.將tools/tolua++文件夾備份,將pkg.zip解壓到tools/tolua++下,然後運行命令行編譯出LuaCocos2d.cpp(這步編譯不會的...去百度)
4.編譯cocos2d-x工程,就可以在lua裏使用cocosguilib裏的類了
使用Hellolua工程跑示例程序:
將bin下面的所有文件夾和lua拷貝到samples\Lua\HelloLua\Resources下
將hellolua項目裏的AppDelegate.cpp的函數applicationDidFinishLaunching()修改一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder); // turn on display FPS pDirector->setDisplayStats( true ); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // register lua engine CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename( "hellogui.lua" ); pEngine->executeScriptFile(path.c_str()); return true ; } |
然後run
lua中UIWidget註冊回調函數的方法
UIWidget :registerEventScript
lua回調示例這樣
1
2
3
4
5
6
|
function eventHandler(eventType) if eventType == "pushDown" then -- do something end end UIWidget:registerEventScript(eventHandler) |
現有eventType爲
"pushDown"
"move"
"releaseUp"
"cancelUp"
"longClick" (這個studio還未實現)
"selected"
"unSelected"
"percentChanged"
"attachWithIME"
"detachWithIME"
"insertText"
"deleteBackward"
"berthToLeftBottom"
"berthToLeftTop"
"berthToRightBottom"
"berthToRightTop"
"berthToLeft"
"berthToTop"
"berthToRight"
"berthToBottom"
"bounceOver"
"bounceToLeftBottom"
"bounceToLeftTop"
"bounceToRightBottom"
"bounceToRightTop"
"bounceToLeft"
"bounceToTop"
"bounceToRight"
"bounceToBottom"
"initChild"
"updateChild"
"scrollToTop"
"scrollToBottom"
"scrollToLeft"
"scrollToRight"
BUG:
CocosGUIExamplesRegisterScene.lua的第87行寫法有誤,將其修改爲UIActionManager:purgeUIActionManager()即可