diff --git a/cocos2d/actions/CCAction.js b/cocos2d/actions/CCAction.js index bbb268309c..2ce7ac7d71 100644 --- a/cocos2d/actions/CCAction.js +++ b/cocos2d/actions/CCAction.js @@ -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); } }, diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 6d9362cf86..14f5ef5b7e 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -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); }); }, diff --git a/jsb/jsb-action.js b/jsb/jsb-action.js index 496a0d9fa2..f2f0659f6f 100644 --- a/jsb/jsb-action.js +++ b/jsb/jsb-action.js @@ -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) { diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index 8c44bc2520..ff8e1db0c9 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -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); }); },