Well, one problem with doing it through JSB is that the renderer doesn’t appear to have bindings, so to do it “properly” you would have to create bindings for the renderer and then bind the director’s getRenderer()
function. Or you could create your own C++ helper class, add a function to call the renderer and then just create bindings for your helper class.
Or you could resort to a quick hack: Add a static function to the JSB for the director to call the renderer’s render function. I have no idea about using the bindings generator (or if it would work for this), but I can tell you how to change the JSB files to achieve this. If you would be comfortable messing around with them, there’s the 3 steps involved. (Hopefully there’s no reason why they didn’t choose to bind the renderer.)
Step 1:
In jsb_cocos2dx_auto.hpp
, find the line bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp);
. Copy and paste directly underneath it and change getInstance
to render
, so you now have:
bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Director_render(JSContext *cx, uint32_t argc, jsval *vp);
Step 2:
In jsb_cocos2dx_auto.cpp
(may take a couple seconds to load because it has over 60,000 lines of code), search for the js_cocos2dx_Director_getInstance
function. Under this function, add:
bool js_cocos2dx_Director_render(JSContext *cx, uint32_t argc, jsval *vp)
{
if (argc == 0) {
cocos2d::Director::getInstance()->getRenderer()->render();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return true;
}
JS_ReportError(cx, "js_cocos2dx_Director_render : wrong number of arguments");
return false;
}
Step 3:
2 functions down from Step 2 there should be the function js_register_cocos2dx_Director
. Inside this you will find the line
static JSFunctionSpec st_funcs[] = {
JS_FN("getInstance", js_cocos2dx_Director_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
Change this to:
static JSFunctionSpec st_funcs[] = {
JS_FN("getInstance", js_cocos2dx_Director_getInstance, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("render", js_cocos2dx_Director_render, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
And you’re done. Step 1 adds the function declaration to the JSB header file. Step 2 adds the code that calls the renderer. And Step 3 basically adds the function to Javascript.
After this, you should be able to call cc.Director.render();