framework version : cocos2d-js 3.0 beta
I want to achieve my action, so I mimic “cc.moveBy” source.
They can run on the web, but an exception occurs on the JSB…
error:"cc.ActionInterval.extend" is not Function!
framework version : cocos2d-js 3.0 beta
I want to achieve my action, so I mimic “cc.moveBy” source.
They can run on the web, but an exception occurs on the JSB…
error:"cc.ActionInterval.extend" is not Function!
cc.ActionInterval is an abstract class in C++, so it doesn’t have an constructor and can’t be extended neither.
What do you want to achieve exactly ? Maybe there are other walk arounds for your problem.
I have a background of 1200 * 480, displayed on the screen split screen scrolling effect.
ps:Both sides use the same image display
update : function(time) {
time = this._computeEaseTime(time);
if (this.target) {
var x = this.deltaRect.x * time;
var y = this.deltaRect.y * time;
var locStartRect = this.startRect;
if (cc.ENABLE_STACKABLE_ACTIONS) {
var targetRectX = this.target.getTextureRect().x;
var targetRectY = this.target.getTextureRect().y;
var locPreviousRect = this.previousRect;
locStartRect.x = locStartRect.x + targetRectX - locPreviousRect.x;
locStartRect.y = locStartRect.y + targetRectY - locPreviousRect.y;
x = x + locStartRect.x;
y = y + locStartRect.y;
locPreviousRect.x = x;
locPreviousRect.y = y;
this.target.setTextureRect(cc.rect(x, y, locStartRect.width, locStartRect.height));
} else {
this.target.setTextureRect(cc.rect(locStartRect.x + x, locStartRect.y + y, locStartRect.width, locStartRect.height));
}
}
}
You can do such update with scheduleUpdate in the class of your background
Yes, I know this method.
cc.CutMoveBy = cc.ActionInterval.extend({
deltaRect : null,
startRect : null,
previousRect : null,
ctor : function(duration, rect) {
cc.ActionInterval.prototype.ctor.call(this);
// init
this.deltaRect = cc.rect(0, 0, 0, 0);
this.startRect = cc.rect(0, 0, 0, 0);
this.previousRect = cc.rect(0, 0, 0, 0);
this.initWithDuration(duration, rect);
},
initWithDuration : function(duration, rect) {
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this.deltaRect = rect;
return true;
}
return false;
},
startWithTarget : function(target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this.previousRect = target.getTextureRect();
this.startRect = target.getTextureRect();
},
/**
* @param {Number}
* time time in seconds
*/
update : function(time) {
time = this._computeEaseTime(time);
if (this.target) {
var x = this.deltaRect.x * time;
var y = this.deltaRect.y * time;
var locStartRect = this.startRect;
if (cc.ENABLE_STACKABLE_ACTIONS) {
var targetRectX = this.target.getTextureRect().x;
var targetRectY = this.target.getTextureRect().y;
var locPreviousRect = this.previousRect;
locStartRect.x = locStartRect.x + targetRectX - locPreviousRect.x;
locStartRect.y = locStartRect.y + targetRectY - locPreviousRect.y;
x = x + locStartRect.x;
y = y + locStartRect.y;
locPreviousRect.x = x;
locPreviousRect.y = y;
this.target.setTextureRect(cc.rect(x, y, locStartRect.width, locStartRect.height));
} else {
this.target.setTextureRect(cc.rect(locStartRect.x + x, locStartRect.y + y, locStartRect.width, locStartRect.height));
}
}
}
});
cc.CutMoveBy.create = function(duration, rect) {
return new cc.CutMoveBy(duration, rect);
};
update : function(dt) {
if (this.firstAction) {
this.firstAction = false;
this.elapsed = 0;
} else
this.elapsed += dt;
var t = this.elapsed / (this.duration > 0.0000001192092896 ? this.duration : 0.0000001192092896);
t = (1 > t ? t : 1);
this.cutMove(t > 0 ? t : 0);
if (t == 1) {
cc.log("over");
this.unscheduleUpdate();
}
},
cutMove : function(time) {
var x = this.deltaRect.x * time;
var y = this.deltaRect.y * time;
var locStartRect = this.startRect;
var targetRectX = this.getTextureRect().x;
var targetRectY = this.getTextureRect().y;
var locPreviousRect = this.previousRect;
locStartRect.x = locStartRect.x + targetRectX - locPreviousRect.x;
locStartRect.y = locStartRect.y + targetRectY - locPreviousRect.y;
x = x + locStartRect.x;
y = y + locStartRect.y;
locPreviousRect.x = x;
locPreviousRect.y = y;
this.setTextureRect(cc.rect(x, y, locStartRect.width, locStartRect.height));
},
Hey, I looked into the new cocos2dx 3.11 js binding and it seems to support cc.ActionInterval bindings (although the C++ CCActionInterval still has no constructor )…is that correct? because I tried to upgrade my project to 3.11 and still getting errors related to this class:
error:"cc.ActionInterval.extend" is not Function!
I tried to use cc.MoveTo.extend (which inherits from ActionInterval) and seems to have JS bindings but i get this weird error (BTW this happens on iPhone device, while the same code works on web)
"js_cocos2dx_ActionInterval_easing : Invalid Native Object"