No, I use cocos2d-x, but not use javscript binding, but I begin to learn how to use it, and I pretend to use it.
My idea is to develop games using cocs2d-html5 and use the JSB to create native apps.
Man I am having the same problem here… I extended the LayerColor as a new class (myLayerColor) and now I want to create it using the .create(cc4b Color4B)…
I could not understand how you solve your problem :/…
In this case using the create is important, but I can not use it direct from the LayerColor.creat, othewise the object created will not be a MyLayerColor, in the other hand I could not manage to access the statics methods from my new class.
Hi Pedro,
I don’t understand exactly what you want.
But I think you create something like this.
var MundoUm = cc.Layer.extend({
//lots of code
});
var MundoUmScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new MundoUm();
layer.init();
this.addChild(layer);
}
});
About the static methods, you can create it in any file that you want.
I create my inside my mainmenu.js
var MainMenu = cc.Layer.extend({
init:function () {
//lots of code
}
});
//register the class name
function Utils(){}
Redirect.goToGame = function()
{ cc.Director.getInstance().replaceScene(new HelloWorldScene()); }
Redirect.goToOptions = function()
{ cc.Director.getInstance().replaceScene(new OptionsScene()); }
Redirect.goToShop = function()
{ cc.Director.getInstance().replaceScene(new ShopScene()); }
Redirect.goToMainMenu = function()
{ cc.Director.getInstance().replaceScene(new MainMenuScene()); }
Redirect.goToMundoUm = function()
{ cc.Director.getInstance().replaceScene(new MundoUmScene()); }
Redirect.goToMundoDois = function()
{ cc.Director.getInstance().replaceScene(new MundoDoisScene()); }
//Global values - constant values
var KDamageShuriken =111;
var KSpeedShuriken =112;
var KRangeShuriken =113;
var KEquippedShuriken= 121;
It’s that you want?
Or your problem is to use the Color4B to create the ColorLayer?
myLayerColor = cc.LayerColor.extend({
ctor:function() {
this.*super;
cc.associateWithNative;
},
init: function {
this.*super(color);
— more code —
},
— more methods —
});
But when creating this layer from anywhere in my code I can’t call it as:
createMyLayer:function(color){
var myLayer = myLayerColor.create(color);
}
Because it can not identify create as a static method from MyLayer, even it being from the LayerColor (what is not wrong, but it would be nice to have).
My workaround is to copy the method create from LayerColor to MyLayer, but I would like to know if there is any other “better way” to solve it.
Hi,
I look in the reference documentation for cocos2d-html5, I see the create method for cc.Layer don’t receive parameters and the create method for cc.LayerColor receive 3 parameters, instead of 1.
No one create method from or inherited by cc.Layer use 1 parameter.
The other two parameters are width and heigth.
Take a look in the documents reference and see this can help you.
The method create from LayerColor can indeed receive just a Color4B, it has some default values for width and height, so they are not needed.
Anyways, even using the 3 parameters it doesn’t work… IMO my question is more regarding the OO in JS than about cocos2D in fact
Nice job with your game athe Google Store, nice to see cocos being used in many ways!
Did u use the binding for Chrome Native or it is just a HTML5 game running?
The init method works for you.
You could use init and release the memory later.
I checked my server now, the game works ok, it only leave a time to begin the first time.
My game only works in Chrome and IE 9(using Windows), safari and firefox got problems.
In Mac, it not works properly in any browser. I don’t know why.