您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x-2.2.0版本的CocoStudio的GUI绑定到lua

2014-01-21 19:02 357 查看


cocos2d-x-2.2.0版本的CocoStudio的GUI绑定到lua

分类: cocos2d-x2013-09-27
16:51 3303人阅读 评论(18) 收藏 举报

cocostudioguicocos2d-xlua

所有testcpp里的widget示例都已实现,实现了一个GuiExample,其他的就留给大家去熟悉.其实无非就是将c代码拷贝到lua里然后修改一点...

代码,pkg和示例

使用步骤:

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()修改一下

[cpp] view
plaincopy





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类型的指针)

[plain] view
plaincopy





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绑定

CCSceneReader补丁pkg

使用方法:

1.先备份tools/tolua++文件夹然后将补丁解压到tools/tolua++下

2.运行命令行编译出LuaCocos2d.cpp

3.将工作项目链接pthreadVCE2.lib和libchipmunk.lib库,编译即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: