Merge pull request #1882 from knoxHuang/v1.6

fix Follow isDone error for fireball/issues/6191
This commit is contained in:
pandamicro
2017-08-04 18:00:07 +08:00
committed by GitHub
+114 -9
View File
@@ -56,7 +56,6 @@ var actionArr = [
'Speed',
'Repeat',
'RepeatForever',
'Follow',
'TargetedAction',
'ActionInterval',
'RotateTo',
@@ -138,7 +137,7 @@ cc.Sequence.prototype._ctor = function (...args) {
cc.sequence = function (...args) {
var paramArray = (args[0] instanceof Array) ? args[0] : args;
return new cc.Sequence(paramArray);
}
};
cc.Spawn.prototype._ctor = function (...args) {
var paramArray = (args[0] instanceof Array) ? args[0] : args;
@@ -161,7 +160,7 @@ cc.Spawn.prototype._ctor = function (...args) {
cc.spawn = function (...args) {
var paramArray = (args[0] instanceof Array) ? args[0] : args;
return new cc.Spawn(paramArray);
}
};
cc.targetedAction = function (target, action) {
return new cc.TargetedAction(target, action);
@@ -174,15 +173,121 @@ cc.TargetedAction.prototype._ctor = function(target, action) {
};
cc.follow = function (followedNode, rect) {
return new cc.Follow(followedNode._sgNode, rect);
return new cc.Follow(followedNode, rect);
};
cc.Follow.prototype.update = function(dt) {
var target = this._getSgTarget();
if (target._owner) {
target._owner.setPosition(target.getPosition());
cc.Follow = cc.BaseJSAction.extend({
_followedNode:null,
_boundarySet:false,
_boundaryFullyCovered:false,
_halfScreenSize:null,
_fullScreenSize:null,
_worldRect:null,
leftBoundary:0.0,
rightBoundary:0.0,
topBoundary:0.0,
bottomBoundary:0.0,
ctor:function (followedNode, rect) {
cc.BaseJSAction.prototype.ctor.call(this);
this._followedNode = null;
this._boundarySet = false;
this._boundaryFullyCovered = false;
this._halfScreenSize = null;
this._fullScreenSize = null;
this.leftBoundary = 0.0;
this.rightBoundary = 0.0;
this.topBoundary = 0.0;
this.bottomBoundary = 0.0;
this._worldRect = cc.rect(0, 0, 0, 0);
if(followedNode)
rect ? this.initWithTarget(followedNode, rect)
: this.initWithTarget(followedNode);
},
clone:function () {
var action = new cc.Follow();
var locRect = this._worldRect;
var rect = new cc.Rect(locRect.x, locRect.y, locRect.width, locRect.height);
action.initWithTarget(this._followedNode, rect);
return action;
},
isBoundarySet:function () {
return this._boundarySet;
},
setBoudarySet:function (value) {
this._boundarySet = value;
},
initWithTarget:function (followedNode, rect) {
if(!followedNode)
throw new Error("cc.Follow.initWithAction(): followedNode must be non nil");
var _this = this;
rect = rect || cc.rect(0, 0, 0, 0);
_this._followedNode = followedNode;
_this._worldRect = rect;
_this._boundarySet = !cc._rectEqualToZero(rect);
_this._boundaryFullyCovered = false;
var winSize = cc.director.getWinSize();
_this._fullScreenSize = cc.p(winSize.width, winSize.height);
_this._halfScreenSize = cc.pMult(_this._fullScreenSize, 0.5);
if (_this._boundarySet) {
_this.leftBoundary = -((rect.x + rect.width) - _this._fullScreenSize.x);
_this.rightBoundary = -rect.x;
_this.topBoundary = -rect.y;
_this.bottomBoundary = -((rect.y + rect.height) - _this._fullScreenSize.y);
if (_this.rightBoundary < _this.leftBoundary) {
_this.rightBoundary = _this.leftBoundary = (_this.leftBoundary + _this.rightBoundary) / 2;
}
if (_this.topBoundary < _this.bottomBoundary) {
_this.topBoundary = _this.bottomBoundary = (_this.topBoundary + _this.bottomBoundary) / 2;
}
if ((_this.topBoundary === _this.bottomBoundary) && (_this.leftBoundary === _this.rightBoundary))
_this._boundaryFullyCovered = true;
}
return true;
},
step:function (dt) {
var target = this.getTarget();
var targetWorldPos = target.convertToWorldSpaceAR(cc.Vec2.ZERO);
var followedWorldPos = this._followedNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
var delta = cc.pSub(targetWorldPos, followedWorldPos);
var tempPos = target.parent.convertToNodeSpaceAR(cc.pAdd(delta, this._halfScreenSize));
if (this._boundarySet) {
if (this._boundaryFullyCovered)
return;
target.setPosition(cc.clampf(tempPos.x, this.leftBoundary, this.rightBoundary), cc.clampf(tempPos.y, this.bottomBoundary, this.topBoundary));
} else {
target.setPosition(tempPos.x, tempPos.y);
}
},
isDone:function () {
return ( !this._followedNode.isRunning() );
},
stop:function () {
this.setTarget(null);
cc.Action.prototype.stop.call(this);
}
};
});
var _FlipX = cc.FlipX;
cc.FlipX = _FlipX.extend({