Hi everybody. Is it possible to extend a class in 100% Javascript without C++ and have it work in both Cocos2d-x JSB and Cocos2d-html5?
The problem is that using something like cc.ActionInterval.extend() works on Cocos2d-html5 but it doesn’t work with Cocos2d-x Javascript bindings because the extended class is not implemented in C++ (from what I can tell).
It’s time consuming to have to create C++ javascript bindings for something as simple as extending an action. And extending / subclassing is a core feature that should be easy to do in 100% javascript.
Is there an easier way? Or something I am missing?
I also met this problem. cc.Action.extend is not available in JSB.
I have to use ‘schedule’ to implement my own ‘action’
countAction: function (widget, duration, from, to) {//{{{
cc.Assert(widget instanceof cc.Node, ‘widget should be an instance of cc.Node’);
cc.Assert(typeof widget.setText == ‘function’, ‘widget.setText is not a function’);
from = from || 0;
to = to || 0;
widget.setText(from.toString());
var speed = (to - from) / duration;
var update = function (dt) {
duration -= dt;
if (duration < 0) {
from = to;
widget.unschedule(update);
} else {
from += speed * dt;
}
widget.setText(Math.floor(from).toString());
};
widget.schedule(update);
},//}}}
I also met this problem. cc.Action.extend is not available in JSB.
I have to use ‘schedule’ to implement my own ‘action’
countAction: function (widget, duration, from, to) {//{{{
cc.Assert(widget instanceof cc.Node, ‘widget should be an instance of cc.Node’);
cc.Assert(typeof widget.setText == ‘function’, ‘widget.setText is not a function’);
from = from || 0;
to = to || 0;
widget.setText(from.toString());
var speed = (to - from) / duration;
var update = function (dt) {
duration -= dt;
if (duration < 0) {
from = to;
widget.unschedule(update);
} else {
from += speed * dt;
}
widget.setText(Math.floor(from).toString());
};
widget.schedule(update);
},//}}}