- 本帖最后由 rrobin 于 2013-9-10 14:43 编辑 *
注意:此代码只针对此网站发布的cocos2dx_v2.1.5b
所有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()修改一下.
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回调示例这样
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”
好了,各位苦逼的程序员,老衲只能帮你们到这里了