Code Monkey home page Code Monkey logo

cocos2dx-luaproxy's Introduction

#cocos2dx-LuaProxy#

Current version: 2.1.5, support cocos2d-x 2.1.5 and 2.2.x
LuaProxy for cocos2d-x, include CocosBuilder support for lua, and other cocos2d-extension support for lua, and easy to use function.
当前版本:2.1.5,支持cocos2d-x 2.1.5及2.2.x
LuaProxy基于cocos2d-x,主要用于支持在Lua中使用CocosBuilder输出的界面、动画文件,以及添加cocos2d扩展库的Lua支持,还有另外一些易用功能。

LuaProxy have been merged in quick-cocos2d-x. LuaProxy已被整合进quick-cocos2d-x。

##For cocos2d-x 3.0 alpha# Changes of 3.0 is huge, I think I'll use more time to port.
And, I hope to support JavaScript Binding, so LuaProxy is going to rename to "ScriptProxy". But lua is main target to support.
Most files had changed name, because this is a new start, for LuaProxy, and your game project.
3.0的改变很巨大,我大概还要一段时间来移植。我希望可以支持JSB,所以LuaProxy要改名为ScriptProxy,但Lua仍然是主要的支持目标。
很多文件会改名,对LuaProxy来说这是一个新的开始,对你的游戏项目如是。

##LuaProxy 2.1.4 for cocos2d-x 2.1.4# Don't add tolua_extensions_ccb_open(lua_State) to AppDelegate.cpp.
For iOS: And remove CCBProxy., Lua_extensions_CCB. at lib/cocos2d/lua/cocos2dx_support (4 files).
请勿添加tolua_extensions_ccb_open(lua_State)的调用。
iOS中要从Xcode工程中移除CCBProxy., Lua_extensions_CCB.(共4个文件)。

##Change Log# 2013-8-27 LuaProxy 2.1.5 up. Rename class CCBProxy -> LuaProxy, supported cocos2d-x 3.0, change directory struct.
2013-6-19 Moved some functions about ui to ui/UIUtil from CCBProxy. Moved UIEventDispatcher into UIUtil.h/.cpp no longer stand alone. Add CameraEyeAction to do some 3d effect.
2013-6-14 Add CCGLProgram support for lua.
2013-6-9 Support cocos2d-x 2.1.3.
2013-5-29 Add two LuaTableView events, and ui/UIUtil for useful functions.
2013-5-16 Add static functions to LuaEventHandler to direct call lua function.
2013-4-8 Add scroll bar support for LuaTableView. Temporary remove support for CCEditBox.
2013-3-28 Fix for support cocos2d-x 2.1.1.
2013-3-22 Bug fix: LuaTableView is "null" userdata in lua. Add LuaCallFuncInterval for call lua function every frame in duration seconds.
2013-3-19 Change main include file name to luaopen_LuaProxy.h - All function useful for lua will be add, not only CC_Extension.

##Step 1 Add LuaProxy files to your project# Create a Lua based cocos2d-x project, or open your project that added Lua support.
Copy LuaProxy directory into Classes, add all file into project (ui/* is optional).

##Step 2 Add C++ Code# Open CCAppDelegate.cpp, add include like this:

#include "tolua/luaopen_LuaProxy.h"

Move to the line that got CCLuaEngine, add this:

luaopen_LuaProxy(pEngine->getLuaState());

Now you can do those things in lua, but we must create a CCBProxy at first, I wrote this in lua:

local proxy = LuaProxy:create()
-- !!
-- If you want to handle CCControlButton, you must retain the proxy,
-- And kept variable "proxy" to global or global table.
-- While the button won't be use, just like scene poped, you'd batter release the proxy.
-- proxy:retain()

##About CCBI#

###Load ccbi made by CocosBuilder# Maybe you have a ccbi file named "ui-start.ccbi", root node typed with "CCLayer", place it in "Resources/ccb", call this in lua:

local n = proxy:readCCBFromFile("ccb/ui-start.ccbi") -- Got a CCNode
local l = tolua.cast(n, "CCLayer") -- Cast the node into CCLayer

Now you can add the "l" into any scene.

###Referrence any node in ccbi# We'd loaded a ccbi as layer, but you want access a CCLabelTTF, marked "owner" and named "label" in CocosBuilder, and a CCControlButton named "button". Just do this:

local lbl = tolua.cast(proxy:getNode"label", "CCLabelTTF")
lbl:setString("some string")
local btn = tolua.cast(proxy:getNode"button", "CCControlButton")

When CCBProxy read ccbi, it has saved all member variable into a CCDictionary.
So if you'd loaded other ccbi and any variable defined same name, the old one will be lost in the CCDictionary.

###Proxy CCControlButton event with any function# There are two way to do the thing.

-- Handle single button event, you must kept the proxy (retain it, release after the button never use.)
proxy:handleButtonEvent(btn, function(s, e) print(s, e) end, 0) -- 0 means UpInside

[Continue Read] (README-02-complexFunc.md)

cocos2dx-luaproxy's People

Contributors

shawnclovie avatar wtyqm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocos2dx-luaproxy's Issues

ccb使用Custom class报错

ccb中Custom class不为空的情况,proxy:readCCBFromFile()这个方法会导致:
Assertion failed: (ccNodeLoadersIterator != this->mCCNodeLoaders.end()), function getCCNodeLoader, file /Users/guxin/Desktop/CocosDragonWtihLua/CocosDragonWtihLua/libs/extensions/CCBReader/CCNodeLoaderLibrary.cpp, line 67.

proxy:readCCBFromFile() 的实现部分ib->registerCCNodeLoader("", ProxyLayerLoader::loader()); 莫非因为第一个参数没有传进来注册导致的?手动增加参数后测试正常。

FYI:http://www.cocos2d-x.org/boards/18/topics/16740

加载第二个lua文件出错

请您帮我排除一下,是不是您的luaproxy 的问题,还是我自己的问题。
我今天写了一个叫fristLevel 的lua,然后游戏结束,我跳转到Gameover 的这个scene 里面。然后我重新调用,打开fristLevel的 那个文件的scene,报错。我打断点调试,发现luaengine,里面的静态成员m_luaengine 有值。请问,是不是您的luaproxy,在使用完之后,需要清空退出,我没有找到相关的函数啊。

Example Support

thank you for your nice work.
is there any example support?

编译出错

LuaEventHandler.hpp:60:7: Expected identifier or '{'

CCEditBox的运行时错误

你好。我想请问下,CCEditBox在运行到tolua_class(l, "CCEditBox", "CCEditBox", "CCControlButton", NULL);时会出现crash。这个bug,大概是什么原因知道吗?有没有一个解决的方向吗?

ccbi读取问题

在ccb里面设置的是横屏的,然后使用luaproxy读取的时候是竖屏的,无论怎样设置Supported Device Ortientations 都不行

Mod to tolua_CCHttpResponse_getResponseData to support binaray data

//CCHttpResponse::getResponseData
static int tolua_CCHttpResponse_getResponseData(lua_State *l){

ifndef TOLUA_RELEASE

tolua_Error err;
if(!tolua_isusertype(l, 1, "CCHttpResponse", 0, &err)){
tolua_error(l,"#ferror in function 'CCHttpResponse.getResponseData'.",&err);
return 0;
}

endif

CCHttpResponse _o = (CCHttpResponse *)tolua_tousertype(l, 1, NULL);
std::vector *data = o->getResponseData();
const char * s = &(_data->begin()); //We can get the raw pointer, no need alloc & copy
lua_pushlstring(l, s, data->size()); // Use lua_pushlstring, and set the right size, if use tolua_pushstring, it will use strlen to compute the buffer size, when the buffer is binary data, it's wrong.
return 1;
}

LuaTableView的一个问题

已经用LuaTableView:createWithHandler创建出一个列表,请问如果数据更新了,列表怎样更新??

attempt to index local 'lbl' (a nil value)

cocos2d-x is 2.1.2, cocosbuilder is 3.0

local lbl = proxy:getNodeWithType("label1", "CCLabelTTF")
lbl:setString("some string")

It says: attempt to index local 'lbl' (a nil value)

MAC some bugs

I am run LuaProxy example in win32 is very well and no bug( use cocos2dx 2.1.2)

but I find some bugs aboat "CCEditBox" on the Mac

bug 1:
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
void CCBProxy::handleEvent(CCEditBox *n, const int handler){
LuaEventHandler *h = this->addHandler(handler, false)->setTypename("CCEditBox");
n->setDelegate(h); //this line doesn't compile on the mac 编译错误,先注释
}

endif

bug 2:
//this line does runtime error on the mac
tolua_cclass(l, "CCEditBox", "CCEditBox", "CCControlButton", NULL);

link error in cocos2d-x 2.1.4f.

I am using cocos2d-x 2.1.4f. I noticed that cocos2d-x has a "CCBProxy.h/cpp" file in the scripting\lua\cocos2dx_support directory. And when I added all the LuaProxy files into my project, I got an error LNK2005: "public: __thiscall CCBProxy::CCBProxy(void)" (??0CCBProxy@@QAE@XZ) 已经在 CCBProxy.obj 中定义

I wonder what should I do now? Thank you.

在lua中使用getUserObject 读取不出来

您好,我使用您的luaProXY 这个包,在lua中读取的ccbi,现在有个问题。
local z_Drinker
local m_Drinker = tolua.cast(Drinker, "CCBAnimationManager")
z_Drinker = m_Drinker:getUserObject()
z_Drinker:runAnimations("he_siwang")
Drinker 是我在Cocosbuilder定义的一个精灵的名字,用ccnode 传出来的。
强转成CCBAnimationManager 然后读取的数据。
在c++ 上可以成功运行。
在lua上不行了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.