From bc10ca822b12d3400d70ead532dd3b6b803e92f4 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 21 Dec 2015 16:24:01 +0800 Subject: [PATCH] refine CCSpriteRender according to low level changes --- cocos2d/core/components/CCSpriteRenderer.js | 128 ++------------------ 1 file changed, 11 insertions(+), 117 deletions(-) diff --git a/cocos2d/core/components/CCSpriteRenderer.js b/cocos2d/core/components/CCSpriteRenderer.js index 161cb2c1fc..13dd38bd94 100644 --- a/cocos2d/core/components/CCSpriteRenderer.js +++ b/cocos2d/core/components/CCSpriteRenderer.js @@ -44,8 +44,6 @@ var SpriteRenderer = cc.Class({ type: cc.SpriteFrame }, _type: SpriteType.SIMPLE, - _isFlippedX: false, - _isFlippedY: false, _useOriginalSize: true, /** @@ -74,11 +72,6 @@ var SpriteRenderer = cc.Class({ var lastSprite = this._sprite; this._sprite = value; if (this._sgNode) { - if (CC_EDITOR) { - if (force) { - this._sgNode._scale9Image = null; - } - } this._applySprite(this._sgNode, lastSprite); // color cleared after reset texture, should reapply color this._sgNode.setColor(this.node._color); @@ -187,8 +180,8 @@ var SpriteRenderer = cc.Class({ * is the whole image. If the shape is the whole texture, set this to the texture's full rect. * @param {Rect} capInsets - The values to use for the cap insets. */ - initWithFile: function (file, rect, capInsets) { - this._sgNode.initWithFile(file, rect, capInsets); + initWithFile: function (file) { + this._sgNode.initWithFile(file); }, /** @@ -202,9 +195,9 @@ var SpriteRenderer = cc.Class({ * @param {SpriteFrame} spriteFrame - The sprite frame object. * @param {Rect} capInsets - The values to use for the cap insets. */ - initWithSpriteFrame: function (spriteFrame, capInsets) { + initWithSpriteFrame: function (spriteFrame) { this._sprite = spriteFrame; - this._sgNode.initWithSpriteFrame(spriteFrame, capInsets); + this._sgNode.initWithSpriteFrame(spriteFrame); }, /** @@ -218,54 +211,22 @@ var SpriteRenderer = cc.Class({ * @param {String} spriteFrameName - The sprite frame name. * @param {Rect} capInsets - The values to use for the cap insets. */ - initWithSpriteFrameName: function (spriteFrameName, capInsets) { - var initialized = this._sgNode.initWithSpriteFrame(spriteFrameName, capInsets); + initWithSpriteFrameName: function (spriteFrameName) { + var initialized = this._sgNode.initWithSpriteFrame(spriteFrameName); if (initialized === false) { return; } this._sprite = this._sgNode.getSprite(); }, - /** - * Creates and returns a new sprite object with the specified cap insets. - * You use this method to add cap insets to a sprite or to change the existing - * cap insets of a sprite. In both cases, you get back a new image and the - * original sprite remains untouched. - * - * @method resizableSpriteWithCapInsets - * @param {Rect} capInsets - The values to use for the cap insets. - * @return {Scale9Sprite} A Scale9Sprite instance. - */ - resizableSpriteWithCapInsets: function (capInsets) { - return this._sgNode.resizableSpriteWithCapInsets(capInsets); - }, - - /** - * Update Scale9Sprite with a specified sprite. - * - * @method updateWithSprite - * @param {SpriteFrame} sprite - A sprite pointer. - * @param {Rect} rect - A delimitation zone. - * @param {Number} rotated - Whether the sprite is rotated or not. - * @param {Size} offset - The offset when slice the sprite. - * @param {Size} originalSize - The origial size of the sprite. - * @param {Rect} capInsets - The Values to use for the cap insets. - * @return {Boolean} True if update success, false otherwise. - */ - updateWithSprite: function (sprite, textureRect, rotated, offset, originalSize, capInsets) { - this._sprite = sprite; - return this._sgNode.updateWithSprite(sprite, textureRect, rotated, offset, originalSize, capInsets); - }, - /** * Sets a new sprite frame to the sprite. * @method setSpriteFrame * @param {SpriteFrame} spriteFrame * @param {Rect} capInsets */ - setSpriteFrame: function (spriteFrame, capInsets) { + setSpriteFrame: function (spriteFrame) { this.sprite = spriteFrame; - this.setCapInsets(capInsets); }, /** @@ -292,24 +253,7 @@ var SpriteRenderer = cc.Class({ * @return {Size} Scale9Sprite's preferred size. */ getPreferredSize: function () { - return this._sgNode.getPreferredSize(); - }, - - /** - * Change the cap inset size. - * @method setCapInsets - * @param {Rect} capInsets - A delimitation zone. - */ - setCapInsets: function (capInsets) { - this._sgNode.setCapInsets(capInsets); - }, - /** - * Query the Scale9Sprite's preferred size. - * @method getCapInsets - * @return {Rect} Scale9Sprite's cap inset. - */ - getCapInsets: function () { - return this._sgNode.getCapInsets(); + return this._sgNode.getContentSize(); }, /** @@ -384,56 +328,6 @@ var SpriteRenderer = cc.Class({ return this._sgNode.getInsetBottom(); }, - /** - * Sets whether the widget should be flipped horizontally or not. - * @method setFlippedX - * @param {Boolean} flippedX - true if the sprite should be flipped horizontally, false otherwise. - */ - setFlippedX: function (flippedX) { - this._isFlippedX = flippedX; - this._sgNode.setFlippedX(flippedX); - }, - - /** - * Returns the flag which indicates whether the widget is flipped horizontally or not. - * - * It only flips the texture of the widget, and not the texture of the widget's children. - * Also, flipping the texture doesn't alter the anchorPoint. - * If you want to flip the anchorPoint too, and/or to flip the children too use: - * widget->setScaleX(sprite->getScaleX() * -1); - * - * @method isFlippedX - * @return {Boolean} true if the sprite is flipped horizontally, false otherwise. - */ - isFlippedX: function () { - return this._isFlippedX; - }, - - /** - * Sets whether the sprite should be flipped vertically or not. - * @method setFlippedY - * @param {Boolean} flippedY - true if the sprite should be flipped vertically, false otherwise. - */ - setFlippedY: function (flippedY) { - this._isFlippedY = flippedY; - this._sgNode.setFlippedY(flippedY); - }, - - /** - * Return the flag which indicates whether the widget is flipped vertically or not. - * - * It only flips the texture of the widget, and not the texture of the widget's children. - * Also, flipping the texture doesn't alter the anchorPoint. - * If you want to flip the anchorPoint too, and/or to flip the children too use: - * widget->setScaleY(widget->getScaleY() * -1); - * - * @method isFlippedY - * @return {Boolean} true if the sprite is flipped vertically, false otherwise. - */ - isFlippedY: function () { - return this._isFlippedY; - }, - onLoad: function () { this._super(); this.node.on('size-changed', this._resized, this); @@ -469,11 +363,11 @@ var SpriteRenderer = cc.Class({ _applySpriteSize: function (node) { var node = node || this._sgNode; if (this._useOriginalSize) { - var rect = this._sprite.getRect(); - node.setPreferredSize(cc.size(rect.width, rect.height)); + var rect = this._sprite.getOriginalSize(); + node.setContentSize(cc.size(rect.width, rect.height)); } else { - node.setPreferredSize(this.node.getContentSize(true)); + node.setContentSize(this.node.getContentSize(true)); } },