From af69bf09889d147ed1c6c2cb0a835b361cc90e14 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 21 Dec 2015 15:46:38 +0800 Subject: [PATCH 01/11] widget's property should be adjusted to fit new position in edit mode --- cocos2d/core/base-ui/CCWidgetManager.js | 42 ++++++++++++++++++++++++- cocos2d/core/event/event-target.js | 2 +- cocos2d/core/platform/CCAssetLibrary.js | 15 ++++++--- test/visual-tests/run-helper.sh | 2 +- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/base-ui/CCWidgetManager.js b/cocos2d/core/base-ui/CCWidgetManager.js index 3ec2633d2f..8aac6aedbf 100644 --- a/cocos2d/core/base-ui/CCWidgetManager.js +++ b/cocos2d/core/base-ui/CCWidgetManager.js @@ -127,19 +127,59 @@ function visitNode (node) { function visit () { var scene = cc.director.getScene(); if (scene) { + widgetManager.isAligning = true; visitNode(scene); + widgetManager.isAligning = false; } } -cc._widgetManager = { +var adjustWidgetToFitPositionInEditor = CC_EDITOR && function (event) { + if (widgetManager.isAligning) { + return; + } + var oldPos = event.detail; + var newPos = this.node.position; + var delta = newPos.sub(oldPos); + if (this.isAlignTop) { + this.top -= delta.y; + } + if (this.isAlignBottom) { + this.bottom += delta.y; + } + if (this.isAlignLeft) { + this.left += delta.x; + } + if (this.isAlignRight) { + this.right -= delta.x; + } + if (this.isAlignHorizontalCenter) { + if (oldPos.x !== newPos.x) { + this.isAlignHorizontalCenter = false; + } + } + if (this.isAlignVerticalCenter) { + if (oldPos.y !== newPos.y) { + this.isAlignVerticalCenter = false; + } + } +}; + +var widgetManager = cc._widgetManager = { + isAligning: false, init: function (director) { director.on(cc.Director.EVENT_BEFORE_VISIT, visit); }, add: function (widget) { widget.node._widget = widget; + if (CC_EDITOR && !cc.engine.isPlaying) { + widget.node.on('position-changed', adjustWidgetToFitPositionInEditor, widget); + } }, remove: function (widget) { widget.node._widget = null; + if (CC_EDITOR && !cc.engine.isPlaying) { + widget.node.off('position-changed', adjustWidgetToFitPositionInEditor, widget); + } }, _getParentSize: getParentSize }; diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index 749c3ada75..01c4134ac5 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -6,7 +6,7 @@ var JS = cc.js; var cachedArray = new Array(16); cachedArray.length = 0; -var _doDispatchEvent = function (owner, event, args) { +var _doDispatchEvent = function (owner, event) { var target, i; event.target = owner; diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index 596bccdd1d..7240fc1b6a 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -380,8 +380,8 @@ var AssetLibrary = { var loaded = img.width > 0 || img.height > 0; if ( !loaded ) { function loadCallback () { - img.removeEventListener('load', loadCallback, false); - img.removeEventListener('error', errorCallback, false); + img.removeEventListener('load', loadCallback); + img.removeEventListener('error', errorCallback); obj[prop] = dependsUrl; --pendingCount; @@ -391,8 +391,15 @@ var AssetLibrary = { } } function errorCallback () { - img.removeEventListener('load', loadCallback, false); - img.removeEventListener('error', errorCallback, false); + img.removeEventListener('load', loadCallback); + img.removeEventListener('error', errorCallback); + + obj[prop] = ''; + --pendingCount; + if (callback && pendingCount === 0) { + callback(); + callback = null; + } } img.addEventListener('load', loadCallback); img.addEventListener('error', errorCallback); diff --git a/test/visual-tests/run-helper.sh b/test/visual-tests/run-helper.sh index 815d6a0abe..f2f05c57d3 100644 --- a/test/visual-tests/run-helper.sh +++ b/test/visual-tests/run-helper.sh @@ -1,3 +1,3 @@ #!/bin/bash sleep 1 -/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome http://127.0.0.1:8512/test/visual-tests/index.html?notrycatch=true +/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome http://127.0.0.1:8512/test/visual-tests/index.html From bc10ca822b12d3400d70ead532dd3b6b803e92f4 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 21 Dec 2015 16:24:01 +0800 Subject: [PATCH 02/11] 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)); } }, From 47f4933de281b9ea0e89d55592ad028d1c0069e5 Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Mon, 21 Dec 2015 16:51:12 +0800 Subject: [PATCH 03/11] add tooltip for node and component title. --- cocos2d/core/components/CCComponent.js | 3 ++- cocos2d/core/utils/base-node.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index 0eea6c9dea..b45fefe518 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -239,7 +239,8 @@ var Component = cc.Class({ } }, displayName: 'Script', - type: cc._Script + type: cc._Script, + tooltip: 'i18n:INSPECTOR.component.script' }, /** diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 28d23399f7..949b470882 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -235,8 +235,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ this._sgNode.rotation = value; this.emit(ROTATION_CHANGED, old); } - }, - tooltip: "The clockwise degrees of rotation relative to the parent" + } }, /** From 610fc56a39db436ce765c192ba851e2eccea324a Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 21 Dec 2015 17:02:46 +0800 Subject: [PATCH 04/11] widget's property should be adjusted to fit new size in edit mode --- cocos2d/core/base-ui/CCWidgetManager.js | 42 +++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/base-ui/CCWidgetManager.js b/cocos2d/core/base-ui/CCWidgetManager.js index 8aac6aedbf..fc8b659aca 100644 --- a/cocos2d/core/base-ui/CCWidgetManager.js +++ b/cocos2d/core/base-ui/CCWidgetManager.js @@ -133,7 +133,7 @@ function visit () { } } -var adjustWidgetToFitPositionInEditor = CC_EDITOR && function (event) { +var adjustWidgetToAllowMovingInEditor = CC_EDITOR && function (event) { if (widgetManager.isAligning) { return; } @@ -164,6 +164,40 @@ var adjustWidgetToFitPositionInEditor = CC_EDITOR && function (event) { } }; +var adjustWidgetToAllowResizingInEditor = CC_EDITOR && function (event) { + if (widgetManager.isAligning) { + return; + } + var oldSize = event.detail; + var newSize = this.node.getContentSize(); + var sizeDelta = cc.p(newSize.width - oldSize.width, newSize.height - oldSize.height); + var anchor = this.node.getAnchorPoint(); + + if (this.isAlignTop) { + this.top -= sizeDelta.y * (1 - anchor.y); + } + if (this.isAlignBottom) { + this.bottom -= sizeDelta.y * anchor.y; + } + if (this.isAlignLeft) { + this.left -= sizeDelta.x * anchor.x; + } + if (this.isAlignRight) { + this.right -= sizeDelta.x * (1 - anchor.x); + } + if (this.isAlignHorizontalCenter) { + if (sizeDelta.x !== 0 && anchor.x !== 0.5) { + this.isAlignHorizontalCenter = false; + } + } + if (this.isAlignVerticalCenter) { + if (sizeDelta.y !== 0 && anchor.y !== 0.5) { + this.isAlignVerticalCenter = false; + } + } +}; + + var widgetManager = cc._widgetManager = { isAligning: false, init: function (director) { @@ -172,13 +206,15 @@ var widgetManager = cc._widgetManager = { add: function (widget) { widget.node._widget = widget; if (CC_EDITOR && !cc.engine.isPlaying) { - widget.node.on('position-changed', adjustWidgetToFitPositionInEditor, widget); + widget.node.on('position-changed', adjustWidgetToAllowMovingInEditor, widget); + widget.node.on('size-changed', adjustWidgetToAllowResizingInEditor, widget); } }, remove: function (widget) { widget.node._widget = null; if (CC_EDITOR && !cc.engine.isPlaying) { - widget.node.off('position-changed', adjustWidgetToFitPositionInEditor, widget); + widget.node.off('position-changed', adjustWidgetToAllowMovingInEditor, widget); + widget.node.off('size-changed', adjustWidgetToAllowResizingInEditor, widget); } }, _getParentSize: getParentSize From 9945eeb55903f5763c103c9c9faf446613a03432 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 21 Dec 2015 17:06:49 +0800 Subject: [PATCH 05/11] spriteRender renname sprite --- cocos2d/core/components/CCButton.js | 8 +- cocos2d/core/components/CCProgressBar.js | 6 +- cocos2d/core/components/CCScrollBar.js | 4 +- .../{CCSpriteRenderer.js => CCSprite.js} | 74 +++++++------------ cocos2d/core/components/index.js | 2 +- cocos2d/deprecated.js | 8 +- test/qunit/unit/test-animation.js | 8 +- test/qunit/unit/test-spriteRenderer.js | 14 ++-- 8 files changed, 52 insertions(+), 72 deletions(-) rename cocos2d/core/components/{CCSpriteRenderer.js => CCSprite.js} (86%) diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index 243aea430d..47f0bfd803 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -108,7 +108,7 @@ var EVENT_HOVER_OUT = 'hover-out'; * When Button state changed: * If Transition type is Button.Transition.NONE, Button will do nothing * If Transition type is Button.Transition.COLOR, Button will change target's color - * If Transition type is Button.Transition.SPRITE, Button will change target SpriteRenderer's sprite + * If Transition type is Button.Transition.SPRITE, Button will change target Sprite's sprite * * Button will trigger 5 events: * Button.EVENT_TOUCH_DOWN @@ -287,7 +287,7 @@ var Button = cc.Class({ * When Button state changed: * If Transition type is Button.Transition.NONE, Button will do nothing * If Transition type is Button.Transition.COLOR, Button will change target's color - * If Transition type is Button.Transition.SPRITE, Button will change target SpriteRenderer's sprite + * If Transition type is Button.Transition.SPRITE, Button will change target Sprite's sprite * @property {cc.Node} target */ target: { @@ -414,7 +414,7 @@ var Button = cc.Class({ _applyTarget: function () { var target = this.target; if (target) { - this._sprite = target.getComponent(cc.SpriteRenderer); + this._sprite = target.getComponent(cc.Sprite); } else { this._sprite = null; @@ -493,7 +493,7 @@ var Button = cc.Class({ } } else if (transition === Transition.SPRITE && this._sprite && sprite) { - this._sprite.sprite = sprite; + this._sprite.spriteframe = sprite; } }, diff --git a/cocos2d/core/components/CCProgressBar.js b/cocos2d/core/components/CCProgressBar.js index 4631baaeec..37a83f9654 100644 --- a/cocos2d/core/components/CCProgressBar.js +++ b/cocos2d/core/components/CCProgressBar.js @@ -127,12 +127,12 @@ var ProgressBar = cc.Class({ properties: { /** - * The targeted SpriteRenderer which will be changed progressively. - *@property {cc.SpriteRenderer} barSprite + * The targeted Sprite which will be changed progressively. + *@property {cc.Sprite} barSprite */ barSprite: { default: null, - type: cc.SpriteRenderer, + type: cc.Sprite, tooltip: 'i18n:COMPONENT.progress.bar_sprite', notify: function() { this._initBarSprite(); diff --git a/cocos2d/core/components/CCScrollBar.js b/cocos2d/core/components/CCScrollBar.js index 0a547867ee..79e97ebfc1 100644 --- a/cocos2d/core/components/CCScrollBar.js +++ b/cocos2d/core/components/CCScrollBar.js @@ -62,11 +62,11 @@ var Scrollbar = cc.Class({ /** * The "handle" part of the scrollbar. - * @property {cc.SpriteRenderer} handle + * @property {cc.Sprite} handle */ handle: { default: null, - type: cc.SpriteRenderer, + type: cc.Sprite, tooltip: 'i18n:COMPONENT.scrollbar.handle', notify: function() { this._onScroll(cc.p(0, 0)); diff --git a/cocos2d/core/components/CCSpriteRenderer.js b/cocos2d/core/components/CCSprite.js similarity index 86% rename from cocos2d/core/components/CCSpriteRenderer.js rename to cocos2d/core/components/CCSprite.js index 13dd38bd94..5c96e8c9a3 100644 --- a/cocos2d/core/components/CCSpriteRenderer.js +++ b/cocos2d/core/components/CCSprite.js @@ -29,7 +29,7 @@ var SpriteType = cc.SpriteType; * @class Sprite * @extends _ComponentInSG */ -var SpriteRenderer = cc.Class({ +var Sprite = cc.Class({ name: 'cc.Sprite', extends: require('./CCComponentInSG'), @@ -39,7 +39,7 @@ var SpriteRenderer = cc.Class({ }, properties: { - _sprite: { + _spriteFrame: { default: null, type: cc.SpriteFrame }, @@ -64,13 +64,13 @@ var SpriteRenderer = cc.Class({ * @property sprite * @type {SpriteFrame} */ - sprite: { + spriteFrame: { get: function () { - return this._sprite; + return this._spriteFrame; }, set: function (value, force) { - var lastSprite = this._sprite; - this._sprite = value; + var lastSprite = this._spriteFrame; + this._spriteFrame = value; if (this._sgNode) { this._applySprite(this._sgNode, lastSprite); // color cleared after reset texture, should reapply color @@ -164,7 +164,7 @@ var SpriteRenderer = cc.Class({ * @return {SpriteFrame} A sprite instance. */ getSprite : function(){ - return this._sprite; + return this._spriteFrame; }, /** @@ -196,7 +196,7 @@ var SpriteRenderer = cc.Class({ * @param {Rect} capInsets - The values to use for the cap insets. */ initWithSpriteFrame: function (spriteFrame) { - this._sprite = spriteFrame; + this._spriteFrame = spriteFrame; this._sgNode.initWithSpriteFrame(spriteFrame); }, @@ -216,7 +216,7 @@ var SpriteRenderer = cc.Class({ if (initialized === false) { return; } - this._sprite = this._sgNode.getSprite(); + this._spriteFrame = this._sgNode.getSprite(); }, /** @@ -226,7 +226,7 @@ var SpriteRenderer = cc.Class({ * @param {Rect} capInsets */ setSpriteFrame: function (spriteFrame) { - this.sprite = spriteFrame; + this.spriteFrame = spriteFrame; }, /** @@ -238,24 +238,6 @@ var SpriteRenderer = cc.Class({ return this._sgNode.getOriginalSize(); }, - /** - * Change the preferred size of Scale9Sprite. - * @method setPreferredSize - * @param {Size} size - A delimitation zone. - */ - setPreferredSize: function (size) { - this.node.setContentSize(size); - }, - - /** - * Query the Scale9Sprite's preferred size. - * @method getPreferredSize - * @return {Size} Scale9Sprite's preferred size. - */ - getPreferredSize: function () { - return this._sgNode.getContentSize(); - }, - /** * Change the left sprite's cap inset. * @method setInsetLeft @@ -338,11 +320,11 @@ var SpriteRenderer = cc.Class({ this.node.off('size-changed', this._resized, this); }, - _applyAtlas: CC_EDITOR && function ( sprite ) { + _applyAtlas: CC_EDITOR && function ( spriteFrame ) { // Set atlas - if (sprite._atlasUuid) { + if (spriteFrame._atlasUuid) { var self = this; - cc.AssetLibrary.loadAsset(sprite._atlasUuid, function(err, asset) { + cc.AssetLibrary.loadAsset(spriteFrame._atlasUuid, function(err, asset) { self._atlas = asset; }); } else { @@ -353,17 +335,17 @@ var SpriteRenderer = cc.Class({ _applyCapInset: function (node) { if (this._type === SpriteType.SLICED) { var node = node || this._sgNode; - node.setInsetTop(this._sprite.insetTop); - node.setInsetBottom(this._sprite.insetBottom); - node.setInsetRight(this._sprite.insetRight); - node.setInsetLeft(this._sprite.insetLeft); + node.setInsetTop(this._spriteFrame.insetTop); + node.setInsetBottom(this._spriteFrame.insetBottom); + node.setInsetRight(this._spriteFrame.insetRight); + node.setInsetLeft(this._spriteFrame.insetLeft); } }, _applySpriteSize: function (node) { var node = node || this._sgNode; if (this._useOriginalSize) { - var rect = this._sprite.getOriginalSize(); + var rect = this._spriteFrame.getOriginalSize(); node.setContentSize(cc.size(rect.width, rect.height)); } else { @@ -375,15 +357,15 @@ var SpriteRenderer = cc.Class({ if (oldSprite && oldSprite.off) { oldSprite.off('load', this._applyCapInset, this); } - if (!this._sprite) return; + if (!this._spriteFrame) return; - sgNode.setSpriteFrame(this._sprite); - var locLoaded = this._sprite.textureLoaded(); + sgNode.setSpriteFrame(this._spriteFrame); + var locLoaded = this._spriteFrame.textureLoaded(); if (!locLoaded) { if ( !this._useOriginalSize ) { - sgNode.setPreferredSize(this.node.getContentSize(true)); + sgNode.setContentSize(this.node.getContentSize(true)); } - this._sprite.once('load', function () { + this._spriteFrame.once('load', function () { this._applyCapInset(); this._applySpriteSize(); }, this); @@ -395,7 +377,7 @@ var SpriteRenderer = cc.Class({ if (CC_EDITOR) { // Set atlas - this._applyAtlas(this._sprite); + this._applyAtlas(this._spriteFrame); } }, @@ -415,10 +397,8 @@ var misc = require('../utils/misc'); var SameNameGetSets = ['atlas', 'capInsets', 'insetLeft', 'insetTop', 'insetRight', 'insetBottom']; var DiffNameGetSets = { type: [ null, 'setRenderingType'], - sprite: ['getSprite', null], - flippedX: ['isFlippedX', 'setFlippedX'], - flippedY: ['isFlippedY', 'setFlippedY'], + spriteFrame: ['getSprite', null], }; -misc.propertyDefine(SpriteRenderer, SameNameGetSets, DiffNameGetSets); +misc.propertyDefine(Sprite, SameNameGetSets, DiffNameGetSets); -cc.SpriteRenderer = module.exports = SpriteRenderer; +cc.Sprite = module.exports = Sprite; diff --git a/cocos2d/core/components/index.js b/cocos2d/core/components/index.js index 4dfb3d8ffe..23dc40bbd7 100644 --- a/cocos2d/core/components/index.js +++ b/cocos2d/core/components/index.js @@ -2,7 +2,7 @@ require('./CCComponent'); require('./CCComponentInSG'); module.exports = [ - require('./CCSpriteRenderer'), + require('./CCSprite'), require('./CCWidget'), require('./CCCanvas'), require('./CCAudioSource'), diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 06b3bb4d4c..153c60d0a8 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -409,23 +409,23 @@ if (CC_DEV) { // cc.SpriteRenderer - markAsRemoved(cc.SpriteRenderer, [ + markAsRemoved(cc.Sprite, [ 'textureLoaded', 'setBlendFunc', 'getBlendFunc', 'setState', 'getState', ]); - provideClearError(cc.SpriteRenderer, { + provideClearError(cc.Sprite, { create: 'node.addComponent', createWithTexture: 'node.addComponent', createWithSpriteFrameName: 'node.addComponent', createWithSpriteFrame: 'node.addComponent', }); - provideClearError(cc.SpriteRenderer.prototype, { + provideClearError(cc.Sprite.prototype, { ignoreAnchorPointForPosition: 'instance.ignoreAnchor', }); - shouldNotUseNodeProp(cc.SpriteRenderer); + shouldNotUseNodeProp(cc.Sprite); // Particle markAsRemoved(cc.ParticleSystem, [ diff --git a/test/qunit/unit/test-animation.js b/test/qunit/unit/test-animation.js index e27c4c6074..f43e257ec2 100644 --- a/test/qunit/unit/test-animation.js +++ b/test/qunit/unit/test-animation.js @@ -92,7 +92,7 @@ test('EntityAnimator.animate', function () { var EntityAnimator = cc._Test.EntityAnimator; var entity = new cc.Node(); - var renderer = entity.addComponent(cc.SpriteRenderer); + var renderer = entity.addComponent(cc.Sprite); renderer.colorProp = Color.BLACK; var animator = new EntityAnimator(entity); @@ -179,7 +179,7 @@ test('AnimationNode', function () { var entity = new cc.Node(); entity.x = 321; - var renderer = entity.addComponent(cc.SpriteRenderer); + var renderer = entity.addComponent(cc.Sprite); renderer.colorProp = Color.BLACK; var animator = new EntityAnimator(entity); @@ -364,12 +364,12 @@ test('initClipData', function () { var entity = new cc.Node(); entity.name = 'foo'; - var renderer = entity.addComponent(cc.SpriteRenderer); + var renderer = entity.addComponent(cc.Sprite); renderer.testColor = Color.BLACK; var childEntity = new cc.Node(); childEntity.name = 'bar'; - var childRenderer = childEntity.addComponent(cc.SpriteRenderer); + var childRenderer = childEntity.addComponent(cc.Sprite); childRenderer.testColor = Color.BLACK; entity.addChild(childEntity); diff --git a/test/qunit/unit/test-spriteRenderer.js b/test/qunit/unit/test-spriteRenderer.js index 96da914761..d4953fc924 100644 --- a/test/qunit/unit/test-spriteRenderer.js +++ b/test/qunit/unit/test-spriteRenderer.js @@ -1,4 +1,4 @@ -largeModule('SpriteRenderer'); +largeModule('Sprite'); asyncTest('basic test', function () { var url = assetDir + '/button.png'; @@ -7,16 +7,16 @@ asyncTest('basic test', function () { cc.director.getScene().addChild(node); node.color = Color.RED; - var render = node.addComponent(cc.SpriteRenderer); + var render = node.addComponent(cc.Sprite); deepEqual(render._sgNode.color, Color.RED, 'color set success'); var newSprite = new cc.SpriteFrame(); - newSprite.initWithTexture(url, cc.rect(0, 0, 10, 10)); - render.sprite = newSprite; - var tex = newSprite.getTexture(); - tex.once('load', function () { - strictEqual(render._sgNode._scale9Image.texture.url, url, 'texture set success'); + var texture = cc.textureCache.addImage(url); + newSprite.setTexture(texture); + render.spriteFrame = newSprite; + render.spriteFrame.once('load', function () { + strictEqual(render._sgNode._resourceData._texture.url, url, 'texture set success'); start(); }); }); From 63c417600b5d60cef44a54d9afc4a0c720af16b5 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 21 Dec 2015 17:18:55 +0800 Subject: [PATCH 06/11] add deprecated info for Sprite --- cocos2d/deprecated.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 06b3bb4d4c..1f86c11cab 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -415,6 +415,15 @@ if (CC_DEV) { 'getBlendFunc', 'setState', 'getState', + 'resizableSpriteWithCapInsets', + 'flippedX', + 'flippedY', + 'setFlippedX', + 'setFlippedY', + 'isFlippedX', + 'isFlippedY', + 'getCapInsets', + 'setCapInsets', ]); provideClearError(cc.SpriteRenderer, { create: 'node.addComponent', @@ -424,6 +433,9 @@ if (CC_DEV) { }); provideClearError(cc.SpriteRenderer.prototype, { ignoreAnchorPointForPosition: 'instance.ignoreAnchor', + getPreferredSize: 'node.getContentSize', + setPreferredSize: 'node.setContentSize', + updateWithSprite: 'spriteFrame' }); shouldNotUseNodeProp(cc.SpriteRenderer); From 38cae90d050beba94a551bfc76c836fd2ea121d1 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 21 Dec 2015 17:43:00 +0800 Subject: [PATCH 07/11] update CCButton and CCSprite and deprecated --- cocos2d/core/components/CCButton.js | 2 +- cocos2d/core/components/CCSprite.js | 24 ++---------------------- cocos2d/deprecated.js | 4 +++- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index 47f0bfd803..9319875045 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -493,7 +493,7 @@ var Button = cc.Class({ } } else if (transition === Transition.SPRITE && this._sprite && sprite) { - this._sprite.spriteframe = sprite; + this._sprite.spriteFrame = sprite; } }, diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 5c96e8c9a3..db297ebc3c 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -158,15 +158,6 @@ var Sprite = cc.Class({ return this.type === cc.SpriteType.SLICED }, - /** - * Get the original no 9-sliced sprite. - * @method getSprite - * @return {SpriteFrame} A sprite instance. - */ - getSprite : function(){ - return this._spriteFrame; - }, - /** * Initializes a 9-slice sprite with a texture file, a delimitation zone and * with the specified cap insets. @@ -216,17 +207,7 @@ var Sprite = cc.Class({ if (initialized === false) { return; } - this._spriteFrame = this._sgNode.getSprite(); - }, - - /** - * Sets a new sprite frame to the sprite. - * @method setSpriteFrame - * @param {SpriteFrame} spriteFrame - * @param {Rect} capInsets - */ - setSpriteFrame: function (spriteFrame) { - this.spriteFrame = spriteFrame; + this._spriteFrame = this._sgNode.getSpriteFrame(); }, /** @@ -396,8 +377,7 @@ var Sprite = cc.Class({ var misc = require('../utils/misc'); var SameNameGetSets = ['atlas', 'capInsets', 'insetLeft', 'insetTop', 'insetRight', 'insetBottom']; var DiffNameGetSets = { - type: [ null, 'setRenderingType'], - spriteFrame: ['getSprite', null], + type: [ null, 'setRenderingType'] }; misc.propertyDefine(Sprite, SameNameGetSets, DiffNameGetSets); diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 5aebc0f2fe..2e5009957c 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -435,7 +435,9 @@ if (CC_DEV) { ignoreAnchorPointForPosition: 'instance.ignoreAnchor', getPreferredSize: 'node.getContentSize', setPreferredSize: 'node.setContentSize', - updateWithSprite: 'spriteFrame' + updateWithSprite: 'spriteFrame', + getSpriteFrame: 'spriteFrame', + setSpriteFrame: 'spriteFrame', }); shouldNotUseNodeProp(cc.Sprite); From e9287d3037bdd8c82f910d539c76797748f65856 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 21 Dec 2015 17:47:55 +0800 Subject: [PATCH 08/11] Improve Scrollview and refine the properties Squashed commit of the following: commit d10bd73f87fae6ba39858e190921155475ede586 Merge: b174d7c 2ed54b8 Author: zilongshanren Date: Mon Dec 21 17:44:25 2015 +0800 Merge remote-tracking branch 'fireball/master' into fixScrollView commit b174d7cd36fffccf78659b4018940d03da5a6587 Author: zilongshanren Date: Mon Dec 21 17:20:53 2015 +0800 fix content size smaller than scrollvie size commit 8a3ff65f1d2f0e1a6a569a037b7fad1ec9e235e8 Author: zilongshanren Date: Mon Dec 21 16:24:45 2015 +0800 add new brake logic commit 84da9372a148caa7fd6518f3d12f5fe191454729 Author: zilongshanren Date: Mon Dec 21 15:05:08 2015 +0800 renaming the properties commit f3c40a8e7ad6e6097bf07399201ac82e8d5fa72b Author: zilongshanren Date: Mon Dec 21 14:21:38 2015 +0800 fix scrollbar positioning commit d3eb25ddd34a6634737804f55b65e355c003938b Author: zilongshanren Date: Mon Dec 21 13:54:05 2015 +0800 fix scrollview doesn't respect to content anchor. --- cocos2d/core/components/CCScrollBar.js | 2 +- cocos2d/core/components/CCScrollView.js | 144 +++++++++++++++--------- 2 files changed, 94 insertions(+), 52 deletions(-) diff --git a/cocos2d/core/components/CCScrollBar.js b/cocos2d/core/components/CCScrollBar.js index 0a547867ee..d9ea2bcaf3 100644 --- a/cocos2d/core/components/CCScrollBar.js +++ b/cocos2d/core/components/CCScrollBar.js @@ -111,7 +111,7 @@ var Scrollbar = cc.Class({ }, _convertToScrollViewSpace: function(content) { - var worldSpacePos = content.convertToWorldSpaceAR(cc.p(0, 0)); + var worldSpacePos = content.convertToWorldSpace(cc.p(0, 0)); var scrollViewSpacePos = this._scrollView.node.convertToNodeSpace(worldSpacePos); return scrollViewSpacePos; }, diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index c85c233810..0ace6d005b 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -123,28 +123,31 @@ var ScrollView = cc.Class({ }, /** - * It determines how quickly the content stop moving. A value of 0 will stop the movement immediately. - * When the deceleration rate is very large, it will takes up too much time to stop the movement. - *@property {Float} decelerationRate + * It determines how quickly the content stop moving. A value of 1 will stop the movement immediately. + * A value of 0 will never stop the movement until it reaches to the boundary of scrollview. + *@property {Float} brake */ - decelerationRate: { - default: 0.5 + brake: { + default: 0.5, + type: 'Float', + range: [0, 1, 0.1] }, /** - * When spring is set, the content will be bounce back when move out of boundary. - *@property {Boolean} spring - */ - spring: { - default: true, - }, - - /** - * The elapse time of bouncing back. A value of 0 will bouncing back immediately. - *@property {Float} elastic + * When elastic is set, the content will be bounce back when move out of boundary. + *@property {Boolean} elastic */ elastic: { - default: 0.1 + default: true + }, + + /** + * The elapse time of bouncing back. A value of 0 will bounce back immediately. + *@property {Float} bounceDuration + */ + bounceDuration: { + default: 1, + range: [0, 10] }, /** @@ -181,12 +184,7 @@ var ScrollView = cc.Class({ return; } - var worldSpacePos = this.node.convertToWorldSpace(position); - var contentParent = this.content.parent; - - var localPositionInParent = contentParent.convertToNodeSpaceAR(worldSpacePos); - - this.content.setPosition(localPositionInParent); + this.content.setPosition(position); this._outOfBoundaryAmountDirty = true; @@ -194,9 +192,7 @@ var ScrollView = cc.Class({ }, getContentPosition: function() { - var contentSize = this.content.getContentSize(); - var contentAnchor = this.content.getAnchorPoint(); - return this._convertToScrollViewSpace(cc.p(-contentSize.width * contentAnchor.x, -contentSize.height * contentAnchor.y)); + return this.content.getPosition(); }, //private methods @@ -218,19 +214,32 @@ var ScrollView = cc.Class({ } }, - start: function() { + _calculateBoundary: function() { var scrollViewSize = this.node.getContentSize(); - this._rightBoundary = scrollViewSize.width; - this._topBoundary = scrollViewSize.height; + + var leftBottomPosition = this._convertToContentParentSpace(cc.p(0, 0)); + this._leftBoundary = leftBottomPosition.x; + this._bottomBoundary = leftBottomPosition.y; + + var topRightPosition = this._convertToContentParentSpace(cc.p(scrollViewSize.width, scrollViewSize.height)); + this._rightBoundary = topRightPosition.x; + this._topBoundary = topRightPosition.y; + }, + + _convertToContentParentSpace: function(position) { + var scrollViewPositionInWorldSpace = this.node.convertToWorldSpace(position); + var contentParent = this.content.parent; + + return contentParent.convertToNodeSpaceAR(scrollViewPositionInWorldSpace); + }, + + start: function() { + this._calculateBoundary(); this._updateScrollBar(0); }, update: function(dt) { - var scrollViewSize = this.node.getContentSize(); - this._rightBoundary = scrollViewSize.width; - this._topBoundary = scrollViewSize.height; - if (this._autoScrolling) { this._processAutoScrolling(dt); } @@ -285,15 +294,17 @@ var ScrollView = cc.Class({ }, _scrollChildren: function(deltaMove) { + deltaMove = this._clampDelta(deltaMove); + var realMove = deltaMove; var outOfBoundary; - if (this.spring) { + if (this.elastic) { outOfBoundary = this._getHowMuchOutOfBoundary(); realMove.x *= (outOfBoundary.x === 0 ? 1 : 0.5); realMove.y *= (outOfBoundary.y === 0 ? 1 : 0.5); } - if (!this.spring) { + if (!this.elastic) { outOfBoundary = this._getHowMuchOutOfBoundary(realMove); realMove = cc.pAdd(realMove, outOfBoundary); } @@ -311,7 +322,22 @@ var ScrollView = cc.Class({ this._onScrollBarTouchBegan(); }, + _clampDelta: function(delta){ + var contentSize = this.content.getContentSize(); + var scrollViewSize = this.node.getContentSize(); + if (contentSize.width <= scrollViewSize.width) { + delta.x = 0; + } + if (contentSize.height <= scrollViewSize.height) { + delta.y = 0; + } + + return delta; + }, + _gatherTouchMove: function(delta) { + delta = this._clampDelta(delta); + while (this._touchMoveDisplacements.length >= NUMBER_OF_GATHERED_TOUCHES_FOR_MOVE_SPEED) { this._touchMoveDisplacements.shift(); this._touchMoveTimeDeltas.shift(); @@ -325,16 +351,18 @@ var ScrollView = cc.Class({ }, _startBounceBackIfNeeded: function() { - if (!this.spring) { + if (!this.elastic) { return false; } var bounceBackAmount = this._getHowMuchOutOfBoundary(); + bounceBackAmount = this._clampDelta(bounceBackAmount); + if (cc.pFuzzyEqual(bounceBackAmount, cc.p(0, 0), EPSILON)) { return false; } - var bounceBackTime = Math.max(this.elastic, 0); + var bounceBackTime = Math.max(this.bounceDuration, 0); this._startAutoScroll(bounceBackAmount, bounceBackTime, true); return true; @@ -353,7 +381,7 @@ var ScrollView = cc.Class({ var bounceBackStarted = this._startBounceBackIfNeeded(); if (!bounceBackStarted && this.inertia) { var touchMoveVelocity = this._calculateTouchMoveVelocity(); - if (!cc.pFuzzyEqual(touchMoveVelocity, cc.p(0, 0), EPSILON) && this.decelerationRate > 0) { + if (!cc.pFuzzyEqual(touchMoveVelocity, cc.p(0, 0), EPSILON) && this.brake < 1) { this._startInertiaScroll(touchMoveVelocity); } } @@ -389,7 +417,7 @@ var ScrollView = cc.Class({ _processAutoScrolling: function(dt) { var isAutoScrollBrake = this._isNecessaryAutoScrollBrake(); - var brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : this.decelerationRate * 5; + var brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1; this._autoScrollAccumulatedTime += dt * (1 / brakingFactor); var percentage = Math.min(1, this._autoScrollAccumulatedTime / this._autoScrollTotalTime); @@ -400,7 +428,7 @@ var ScrollView = cc.Class({ var newPosition = cc.pAdd(this._autoScrollStartPosition, cc.pMult(this._autoScrollTargetDelta, percentage)); var reachedEnd = (percentage === 1); - if (this.spring) { + if (this.elastic) { var brakeOffsetPosition = cc.pSub(newPosition, this._autoScrollBrakingStartPosition); if (isAutoScrollBrake) { brakeOffsetPosition = cc.pMult(brakeOffsetPosition, brakingFactor); @@ -431,7 +459,21 @@ var ScrollView = cc.Class({ _startAttenuatingAutoScroll: function(deltaMove, initialVelocity) { var time = this._calculateAutoScrollTimeByInitalSpeed(cc.pLength(initialVelocity)); - this._startAutoScroll(deltaMove, time, true); + var originalMoveLength = cc.pLength(deltaMove); + + var targetDelta = cc.pNormalize(deltaMove); + var contentSize = this.content.getContentSize(); + var scrollviewSize = this.node.getContentSize(); + + targetDelta = cc.p(targetDelta.x * (contentSize.width - scrollviewSize.width) * (1 - this.brake), + targetDelta.y * (contentSize.height - scrollviewSize.height) * (1 - this.brake)); + + targetDelta = cc.pAdd(deltaMove, targetDelta); + var factor = cc.pLength(targetDelta) / originalMoveLength; + + time = time * factor; + + this._startAutoScroll(targetDelta, time, true); }, _calculateAutoScrollTimeByInitalSpeed: function(initalSpeed) { @@ -487,12 +529,6 @@ var ScrollView = cc.Class({ return result; }, - _convertToScrollViewSpace: function(position) { - var contentWorldPosition = this.content.convertToWorldSpaceAR(position); - - return this.node.convertToNodeSpace(contentWorldPosition); - }, - _moveContent: function(deltaMove, canStartBounceBack) { var adjustedMove = this._flattenVectorByDirection(deltaMove); @@ -503,29 +539,33 @@ var ScrollView = cc.Class({ var outOfBoundary = this._getHowMuchOutOfBoundary(); this._updateScrollBar(outOfBoundary); - if (this.spring && canStartBounceBack) { + if (this.elastic && canStartBounceBack) { this._startBounceBackIfNeeded(); } }, + _getContentLeftBoundary: function() { var contentPos = this.getContentPosition(); - return contentPos.x; + var leftBoundary = contentPos.x - this.content.getAnchorPoint().x * this.content.getContentSize().width; + return leftBoundary; }, _getContentRightBoundary: function() { var contentSize = this.content.getContentSize(); - return this._convertToScrollViewSpace(cc.p(contentSize.width, contentSize.height)).x; + return this._getContentLeftBoundary() + contentSize.width; }, _getContentTopBoundary: function() { var contentSize = this.content.getContentSize(); - return this._convertToScrollViewSpace(cc.p(contentSize.width, contentSize.height)).y; + return this._getContentBottomBoundary() + contentSize.height; }, _getContentBottomBoundary: function() { - return this.getContentPosition().y; + var contentPos = this.getContentPosition(); + var bottomBoundary = contentPos.y - this.content.getAnchorPoint().y * this.content.getContentSize().height; + return bottomBoundary; }, _getHowMuchOutOfBoundary: function(addition) { @@ -552,6 +592,8 @@ var ScrollView = cc.Class({ this._outOfBoundaryAmountDirty = false; } + outOfBoundaryAmount = this._clampDelta(outOfBoundaryAmount); + return outOfBoundaryAmount; }, From 8de4485e8da3ce85ad14553bfb992ae2f614196e Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 21 Dec 2015 17:49:37 +0800 Subject: [PATCH 09/11] update test-spriteRenderer --- test/qunit/unit/test-spriteRenderer.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/qunit/unit/test-spriteRenderer.js b/test/qunit/unit/test-spriteRenderer.js index d4953fc924..5611dee542 100644 --- a/test/qunit/unit/test-spriteRenderer.js +++ b/test/qunit/unit/test-spriteRenderer.js @@ -15,8 +15,13 @@ asyncTest('basic test', function () { var texture = cc.textureCache.addImage(url); newSprite.setTexture(texture); render.spriteFrame = newSprite; - render.spriteFrame.once('load', function () { + if (!texture.isLoaded()) { + render.spriteFrame.once('load', function () { + strictEqual(render._sgNode._resourceData._texture.url, url, 'texture set success'); + start(); + }); + } + else { strictEqual(render._sgNode._resourceData._texture.url, url, 'texture set success'); - start(); - }); + } }); From 5903ce5646fd1779c5f3f2eb4195b2a4b62f2eb6 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 21 Dec 2015 17:57:13 +0800 Subject: [PATCH 10/11] fix CCSprite bug --- cocos2d/core/components/CCSprite.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index db297ebc3c..5cec8b5457 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -340,7 +340,6 @@ var Sprite = cc.Class({ } if (!this._spriteFrame) return; - sgNode.setSpriteFrame(this._spriteFrame); var locLoaded = this._spriteFrame.textureLoaded(); if (!locLoaded) { if ( !this._useOriginalSize ) { From cd9fab1107e7bbff2cb19c75cab19e304b7e9832 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 21 Dec 2015 18:29:00 +0800 Subject: [PATCH 11/11] Revert "fix CCSprite bug" --- cocos2d/core/components/CCSprite.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 5cec8b5457..db297ebc3c 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -340,6 +340,7 @@ var Sprite = cc.Class({ } if (!this._spriteFrame) return; + sgNode.setSpriteFrame(this._spriteFrame); var locLoaded = this._spriteFrame.textureLoaded(); if (!locLoaded) { if ( !this._useOriginalSize ) {