Quick-cocos2d-x 3.3 final in CC. Cardinalsplineto:create Exporting to Lua

Source: Internet
Author: User



Recently done a Quick-cocos2d-x 3.3 final project using the curve motion Cardinalspline, found CC. Cardinalsplineby:create is available, but CC. Cardinalsplineto:create but is an empty value error, let me feel some doubts, and later found a friend with my problem, http://www.cocoachina.com/bbs/read.php? Tid-273815.html, it is true that cc.CardinalSplineTo:create is not exported to LUA, but its implementation has already been done on the C + + side.

If we are going to run CC on the simulator. Cardinalsplineto:create, we'll find the lua_cocos2dx_ in the quick-3.3\cocos\scripting\lua-bindings\manual\cocos2d directory first. Manual.cpp file, open after the global search Cardinalsplineto, found no search, but cardinalsplineby can be searched, so we can imitate Cardinalsplineby, Cardinalsplineto exported to the LUA side use 。 There are three places to add changes:

1.

int register_all_cocos2dx_manual (lua_state* tolua_s) {if (NULL = = tolua_s) return 0;    Extendnode (tolua_s);    Extendscene (tolua_s);    Extendlayer (tolua_s);    Extendmenuitem (tolua_s);    Extendmenuitemimage (tolua_s);    Extendmenuitemlabel (tolua_s);    Extendmenuitemfont (tolua_s);    Extendmenuitemsprite (tolua_s);    Extendmenuitemtoggle (tolua_s);    Extendmenu (tolua_s);    Extendscheduler (tolua_s);    Extendsequence (tolua_s);    Extendcallfunc (tolua_s);    Extendspawn (tolua_s);    Extendcardinalsplineby (tolua_s); Extendcardinalsplineto (tolua_s);    This line is added in the Extendcatmullromby (tolua_s);    Extendcatmullromto (tolua_s);    Extendbezierby (tolua_s);    Extendbezierto (tolua_s);    Extenddrawnode (tolua_s);    Extendsprite (tolua_s);    Extendlayercolor (tolua_s);    Extendlayermultiplex (tolua_s);    Extendparticlesystem (tolua_s);    Extendfileutils (tolua_s);    Extenduserdefault (tolua_s);    Extendglprogram (tolua_s);    Extendtexture2d (tolua_s); Extendspritebatchnode (tolua_s);    Extendeventlistenerkeyboard (tolua_s);    Extendeventlistenertouchonebyone (tolua_s);    Extendeventlistenertouchallatonce (tolua_s);    Extendeventlistenermouse (tolua_s);    Extendeventlistenercustom (tolua_s);    Extendeventlisteneracceleration (tolua_s);    Extendactioncamera (tolua_s);        Extendgridaction (tolua_s);    Extendmotionstreak (tolua_s);    Extendatlasnode (tolua_s);    Extendparticlebatchnode (tolua_s);    Extendlabel (tolua_s);    Extendtmxtiledmap (tolua_s);    Extendconsole (tolua_s);    Extendglprogramstate (tolua_s);    Extendorbitcamera (tolua_s);    Extendtmxlayer (tolua_s);    Extendapplication (tolua_s);    Extendtexturecache (tolua_s);    Extendglview (tolua_s);    Extendcamera (tolua_s); return 0;}

2.

int lua_cocos2d_cardinalsplineto_create (lua_state* tolua_s) {if (NULL = = tolua_s) return 0;    int argc = 0;    bool OK = true;    #if cocos2d_debug >= 1 tolua_error tolua_err; if (!tolua_isusertable (tolua_s,1, "CC").        Cardinalsplineto ", 0,&tolua_err)) goto tolua_lerror; #endif argc = Lua_gettop (tolua_s)-1;        if (argc = = 3) {Double dur = 0.0; OK &= luaval_to_number (tolua_s, 2, &dur, "CC.        Cardinalsplineto:create ");                if (!ok) return 0;        int num = 0;        COCOS2D::VEC2 *arr = NULL; OK &= luaval_to_array_of_vec2 (tolua_s, 3, &arr, &num, "CC.        Cardinalsplineto:create ");                if (!ok) return 0;        Double ten = 0.0; OK &= luaval_to_number (tolua_s, 4, &ten, "CC.        Cardinalsplineto:create ");            if (!ok) {Cc_safe_delete_array (arr);        return 0; } if (num > 0) {pointarray* points= Pointarray::create (num);                if (NULL = = points) {Cc_safe_delete_array (arr);            return 0;            } for (int i = 0; i < num; i++) {points->addcontrolpoint (arr[i]);            } cc_safe_delete_array (arr);            cardinalsplineto* Tolua_ret = Cardinalsplineto::create (dur, points, ten); if (NULL! = tolua_ret) {int nID = (tolua_ret)?                (int) tolua_ret->_id:-1; int* Pluaid = (tolua_ret)?                &tolua_ret->_luaID:NULL; Toluafix_pushusertype_ccobject (tolua_s, NID, Pluaid, (void*) Tolua_ret, "CC.                Cardinalsplineto ");            return 1; }}} lual_error (tolua_s, "%s has wrong number of arguments:%d, was expecting%d\n", "CC.    Cardinalsplineto:create ", argc, 3);    return 0; #if cocos2d_debug >= 1tolua_lerror:tolua_error (tolua_s, "#ferror in function"Lua_cocos2d_cardinalsplineto_create '. ", &tolua_err); return 0; #endif}


3.

static void Extendcardinalsplineto (lua_state* tolua_s) {    lua_pushstring (tolua_s, "CC"). Cardinalsplineto ");    Lua_rawget (tolua_s,lua_registryindex);    if (lua_istable (tolua_s,-1))    {        lua_pushstring (tolua_s, "create");        Lua_pushcfunction (tolua_s,lua_cocos2d_cardinalsplineto_create);        Lua_rawset (tolua_s,-3);    }    Lua_pop (tolua_s, 1);}


Where the 1-Step annotated line is added to the corresponding position, and 2 and 3 are directly to the file.

Now that we open the Quick-3.3\quick\player\proj.win32\player.sln file, build the project, compile it, we can see that the Cardinalsplineto in our player is no longer in control.

If you want to run the Android creates Macintosh package, we can open it in the \frameworks\cocos2d-x\cocos\scripting\lua-bindings\manual\cocos2d directory under the current project Lua_ Cocos2dx_manual.cpp file, follow the previous three steps to modify the add, and then recompile, run Build_native.bat, packaged on the phone.




Quick-cocos2d-x 3.3 final in CC. Cardinalsplineto:create Exporting to Lua

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.