所有testcpp裏的widget示例都已實現,實現了一個GuiExample,其他的就留給大家去熟悉.其實無非就是將c代碼拷貝到lua裏然後修改一點...
使用步驟:
1.解壓下載包
2.將extensions下的Cocostudio/GUI文件夾備份,然後用解壓的GUI文件夾覆蓋原文件夾
3.將tools/tolua++文件夾備份,將pkg.zip解壓到tools/tolua++下,然後運行命令行編譯出LuaCocos2d.cpp(這步編譯不會的...去百度)
4.編譯cocos2d-x工程,就可以在lua裏使用Cocostudio的GUI裏的類了
使用Hellolua工程跑示例程序:
將bin下面的所有文件夾和lua拷貝到samples\Lua\HelloLua\Resources下
將hellolua項目裏的AppDelegate.cpp的函數applicationDidFinishLaunching()修改一下
- 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回調示例這樣 (這裏和v2.1.5不一樣,多返回了一個調用者的UIWidget類型的指針)
- function HandleEvent(type,widget)
- if type == "pushDown" then
- -- do something
- end
- end
現有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"
增加CCSSceneReader綁定
使用方法:
1.先備份tools/tolua++文件夾然後將補丁解壓到tools/tolua++下
2.運行命令行編譯出LuaCocos2d.cpp
3.將工作項目鏈接pthreadVCE2.lib和libchipmunk.lib庫,編譯即可
同事完成了完整示例,在此放上