所有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()即可