COCOS JSBinding Workflow
Setup JSB Enviroment
initRegister
initRegister
Add registerDefaultClasses
for later Class
&& Functions
registeration
addRegisterCallback
addRegisterCallback
Add Native cocos Class
to list for later Class
&& Functions
registeration
createGlobalContext
createGlobalContext
Setup SpiderMonkey Enviroment
jsb_prepare.js
jsb_prepare.js
Register some Functions
in javascript
Register registrationList
registrationList
Register registerDefaultClasses
registerDefaultClasses
Register cc
namespace
cc
namespaceRegister global Functions
Functions
To use in javascript
Register register_all_cocos2dx
register_all_cocos2dx
Register js_register_cocos2dx_Node
js_register_cocos2dx_Node
Register Native cocos::Node Class
with Functions
and Properties
Then we can use cc.Node
in javascript
And the Bind Native Function
will be called:
js_cocos2dx_Node_constructor
js_cocos2dx_Node_addChild
Add to _js_global_type_map
_js_global_type_map
Add the cocos::Node
class type to _js_global_type_map
for later Object
creation.
Register Other Native Classes
Classes
jsb_boot.js
jsb_boot.js
Prepare boot enviroment in javascript
Create Cocos Object
Call new cc.Sprite("xxx.png")
from javascript
new cc.Sprite("xxx.png")
from javascript
Trigger ctor
in C++
ctor
in C++
Create NativeObject
cocos::Sprite
NativeObject
cocos::Sprite
Create JSObject
JSObject
Bind NativeObject
with JSObject
NativeObject
with JSObject
Add JSObject
to GC Root
JSObject
to GC Root
Return created Object
to javascript
Object
to javascript
Call _ctor
in javascript
if any from C++
_ctor
in javascript
if any from C++
jsb_create_apis.js
Trigger initWithFile
in C++
initWithFile
in C++
Try to find the NativeObject
(cobj
) bind with the JSObject
NativeObject
(cobj
) bind with the JSObject
Call initWithFile
on NativeObject
with param
initWithFile
on NativeObject
with param
Remove Cocos Object
Call removeFromParentAndCleanup
from javascript
removeFromParentAndCleanup
from javascript
Trigger removeFromParentAndCleanup
in C++
removeFromParentAndCleanup
in C++
Try to find the NativeObject
bind to the JSObject
when created
NativeObject
bind to the JSObject
when createdCall removeFromParent
on NativeObject
with param
removeFromParent
on NativeObject
with param
C++
do the remove
stuffs
C++
do the remove
stuffsTrigger cocos::Ref
destructor
cocos::Ref
destructor
Trigger removeScriptObjectByObject
in C++
removeScriptObjectByObject
in C++
Find the JSObject
bind to the NativeObject
JSObject
bind to the NativeObject
Remove the JSObject
from GC Root
JSObject
from GC Root
Remove the proxy
proxy
Event Register in Cocos
Call addCustomListener
from javascript
addCustomListener
from javascript
Trigger addCustomEventListener
in C++
addCustomEventListener
in C++
Check Function
Function
Create JSFunctionWrapper
with this
and onGameShow
JSFunctionWrapper
with this
and onGameShow
Create a lambda
for Callback
with data
lambda
for Callback
with dataCreate cocos2d::EventListenerCustom
cocos2d::EventListenerCustom
Return cocos2d::EventListenerCustom
to javascript
cocos2d::EventListenerCustom
to javascript
Event Dispatch in Cocos
Call dispatchCustomEvent
from javascript
dispatchCustomEvent
from javascript
Create cc.EventCustom
in javascript
cc.EventCustom
in javascript
Trigger EventCustom_constructor
in C++
EventCustom_constructor
in C++
Set user data in javascript
javascript
**User data is not passed to C++
, stored in javascript
Call dispatchEvent
dispatchEvent
Trigger EventDispatcher_dispatchEvent
in C++
EventDispatcher_dispatchEvent
in C++
Trigger stored lamba
function
lamba
functionJSAPI
invoke
called
JSAPI
invoke
calledjavascript
receive event with data
javascript
receive event with dataGet user data stored in javascript
javascript
CallFunc in Cocos
Call cc.callFunc
in javascript
cc.callFunc
in javascript
Trigger CallFunc_ctor
in C++
CallFunc_ctor
in C++
Trigger _ctor
in javascript
_ctor
in javascript
Trigger initWithFunction
in C++
initWithFunction
in C++
Create JSCallbackWrapper
to keep the param
JSCallbackWrapper
to keep the param
target
selector
data
Add a lamba
function to NativeObject
lamba
function to NativeObject
Trigger lamba
from C++
lamba
from C++
Trigger callback
in javascript
callback
in javascript
Schedule in Cocos
Call schedule
in javascript
schedule
in javascript
Trigger node_schedule
in C++
node_schedule
in C++
Get the Schedule Object
bind to the NativeObject
Schedule Object
bind to the NativeObject
Create a JSScheduleWrapper
to keep params
JSScheduleWrapper
to keep params
Call schedual
function on the NativeObject
schedual
function on the NativeObject
Trigger JSScheduleWrapper::scheduleFunc
Trigger callback
in javascript
callback
in javascript
Last updated
Was this helpful?