fix Follow error, for #fireball/issues/3409

This commit is contained in:
knoxHuang
2016-06-29 15:30:12 +08:00
parent 286a6206ca
commit d7ac3f7fa6
4 changed files with 19 additions and 9 deletions
+7 -6
View File
@@ -528,19 +528,20 @@ cc.Follow = cc.Action.extend({
},
step:function (dt) {
var tempPosX = this._followedNode.x;
var tempPosY = this._followedNode.y;
tempPosX = this._halfScreenSize.x - tempPosX;
tempPosY = this._halfScreenSize.y - tempPosY;
var targetWorldPos = this.target.convertToWorldSpaceAR(cc.Vec2.ZERO);
var followedWorldPos = this._followedNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
// compute the offset between followed and target node
var delta = cc.pSub(targetWorldPos, followedWorldPos);
var tempPos = this.target.parent.convertToNodeSpaceAR(cc.pAdd(delta, this._halfScreenSize));
if (this._boundarySet) {
// whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
if (this._boundaryFullyCovered)
return;
this.target.setPosition(cc.clampf(tempPosX, this.leftBoundary, this.rightBoundary), cc.clampf(tempPosY, this.bottomBoundary, this.topBoundary));
this.target.setPosition(cc.clampf(tempPos.x, this.leftBoundary, this.rightBoundary), cc.clampf(tempPos.y, this.bottomBoundary, this.topBoundary));
} else {
this.target.setPosition(tempPosX, tempPosY);
this.target.setPosition(tempPos.x, tempPos.y);
}
},
+4 -2
View File
@@ -209,7 +209,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
// WidgetManager
cc._widgetManager.init(this);
if (cc._widgetManager) {
cc._widgetManager.init(this);
}
},
/**
@@ -645,7 +647,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
// Delay run / replace scene to the end of the frame
this.once(cc.Director.EVENT_AFTER_DRAW, function () {
this.once(cc.Director.EVENT_AFTER_UPDATE, function () {
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
});
},
+7
View File
@@ -116,6 +116,13 @@ cc.follow = function (followedNode, rect) {
return new cc.Follow(followedNode._sgNode, rect);
};
cc.Follow.prototype.update = function(dt) {
var target = this.getTarget();
if (target._owner) {
target._owner.setPosition(target.getPosition());
}
};
// Special call func
cc.callFunc = function (selector, selectorTarget, data) {
var callback = function (sender, data) {
+1 -1
View File
@@ -203,7 +203,7 @@ cc.js.mixin(cc.director, {
}
// Delay run / replace scene to the end of the frame
this.once(cc.Director.EVENT_AFTER_DRAW, function () {
this.once(cc.Director.EVENT_AFTER_UPDATE, function () {
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
});
},