Im new with cocos and js bindings and was wondering how to pass values betwen them. With this code i would like to do part of procesing in each of them.
1 Load image in c*+ and pass it to js
2 passing layer from js to c*+ and draw it
I can pass strings having problem with layers and sprite.
c++ code
Sprite* SimpleNativeClass::PassSpriteToJS()
{
Sprite *test = Sprite::create("res/HelloWorld.png" );
return test;
}
void SimpleNativeClass::PassLayerToCpp(cocos2d::Layer layer)
{
Sprite *img = Sprite::create("res/HelloWorld.png" );
layer.addChild(img);
}
js code
var MyScene = cc.Scene.extend({
ctor:function() {
this._super();
cc.associateWithNative( this, cc.Scene );
},
onEnter:function () {
this._super();
var layer = new MyLayer();
this.addChild(layer);
layer.init();
var x = new SimpleNativeClass();
x.PassLayerToCpp(layer);
this.sprite = x.PassSpriteToJS();
//this.sprite = cc.Sprite.create("res/HelloWorld.png");// works
layer.addChild(this.sprite);
}
});