From d013bde0fc039fd705524e4ad4b4e7d597a50d5c Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 13 Sep 2016 14:19:33 +0800 Subject: [PATCH] fix FlipX and FilpY bug for #fireball/issues/4156 --- cocos2d/actions/CCActionInstant.js | 4 +- jsb/jsb-action.js | 64 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/cocos2d/actions/CCActionInstant.js b/cocos2d/actions/CCActionInstant.js index 37b3686aa2..74768e4ef7 100644 --- a/cocos2d/actions/CCActionInstant.js +++ b/cocos2d/actions/CCActionInstant.js @@ -259,7 +259,7 @@ cc.FlipX = cc.ActionInstant.extend({ }, update:function (dt) { - this.target.scaleX = Math.abs(this.target.scaleX) * (this._flippedX ? 1 : -1); + this.target.scaleX = Math.abs(this.target.scaleX) * (this._flippedX ? -1 : 1); }, reverse:function () { @@ -315,7 +315,7 @@ cc.FlipY = cc.ActionInstant.extend({ }, update:function (dt) { - this.target.scaleY = Math.abs(this.target.scaleY) * (this._flippedX ? 1 : -1); + this.target.scaleY = Math.abs(this.target.scaleY) * (this._flippedY ? -1 : 1); }, reverse:function () { diff --git a/jsb/jsb-action.js b/jsb/jsb-action.js index 39e2945b6c..a3fdf74b44 100644 --- a/jsb/jsb-action.js +++ b/jsb/jsb-action.js @@ -133,6 +133,70 @@ cc.Follow.prototype.update = function(dt) { } }; +var _FlipX = cc.FlipX; +cc.FlipX = _FlipX.extend({ + _flippedX:false, + + ctor:function(flip){ + _FlipX.prototype.ctor.call(this); + this.initWithFlipX(flip); + }, + + initWithFlipX:function (flip) { + this._flippedX = !!flip; + return true; + }, + + update:function (dt) { + var target = this.getTarget(); + target.scaleX = Math.abs(target.scaleX) * (this._flippedX ? -1 : 1); + }, + + reverse:function () { + return new cc.FlipX(!this._flippedX); + }, + + clone:function(){ + return new cc.FlipX(this._flippedX); + } +}); + +cc.flipX = function (flip) { + return new cc.FlipX(flip); +}; + +var _FlipY = cc.FlipY; +cc.FlipY = _FlipY.extend({ + _flippedY:false, + + ctor: function(flip){ + _FlipY.prototype.ctor.call(this); + this.initWithFlipY(flip); + }, + + initWithFlipY:function (flip) { + this._flippedY = !!flip; + return true; + }, + + update:function (dt) { + var target = this.getTarget(); + target.scaleY = Math.abs(target.scaleY) * (this._flippedY ? -1 : 1); + }, + + reverse:function () { + return new cc.FlipY(!this._flippedY); + }, + + clone:function(){ + return new cc.FlipY(this._flippedY); + } +}); + +cc.flipY = function (flip) { + return new cc.FlipY(flip); +}; + function setRendererVisibility (sgNode, toggleVisible, visible) { if (!sgNode) { return; } var _renderComps = sgNode._owner.getComponentsInChildren(cc._SGComponent);