mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
fix Follow error, for #fireball/issues/3409
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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
@@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user