From 45657da7503f1c61db451e5b48adbb584223dfff Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 11 Dec 2015 13:42:42 +0800 Subject: [PATCH 1/3] Fix issues for jsb build --- cocos2d/core/components/CCSpriteRenderer.js | 12 +- cocos2d/core/platform/CCAssetLibrary.js | 2 +- cocos2d/core/utils/base-node.js | 131 +++++-- jsb_polyfill.js | 377 ++++++++++++++++++++ 4 files changed, 477 insertions(+), 45 deletions(-) create mode 100644 jsb_polyfill.js diff --git a/cocos2d/core/components/CCSpriteRenderer.js b/cocos2d/core/components/CCSpriteRenderer.js index 9d5232eb6c..327d4bf803 100644 --- a/cocos2d/core/components/CCSpriteRenderer.js +++ b/cocos2d/core/components/CCSpriteRenderer.js @@ -459,18 +459,16 @@ var SpriteRenderer = cc.Class({ } }, - _applySprite: function (node, oldSprite) { + _applySprite: function (sgNode, oldSprite) { if (oldSprite) { oldSprite.off('load', this._applyCapInset, this); } if (!this._sprite) { return; } - node._spriteRect = cc.rect(0, 0); - node._originalSize = cc.size(0, 0); - node.initWithSpriteFrame(this._sprite); + sgNode.initWithSpriteFrame(this._sprite, cc.rect(0, 0, 0, 0)); var locLoaded = this._sprite.textureLoaded(); if (!locLoaded) { if ( !this._useOriginalSize ) { - node.setPreferredSize(this.node.getContentSize(true)); + sgNode.setPreferredSize(this.node.getContentSize(true)); } this._sprite.once('load', function () { this._applyCapInset(); @@ -478,8 +476,8 @@ var SpriteRenderer = cc.Class({ }, this); } else { - this._applyCapInset(node); - this._applySpriteSize(node); + this._applyCapInset(sgNode); + this._applySpriteSize(sgNode); } }, diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index 3be5c8113d..8907d96766 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -356,7 +356,7 @@ var AssetLibrary = { */ // load depends assets - for (var i = 0, len = _tdInfo.uuidList.length; i < len; i++) { + for (var i = 0; i < _tdInfo.uuidList.length; i++) { var dependsUuid = _tdInfo.uuidList[i]; (function (dependsUuid, obj, prop) { AssetLibrary.queryAssetInfo(dependsUuid, function (err, dependsUrl, isRawAsset) { diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index c951d0bdc9..b9b3db7d46 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -24,7 +24,6 @@ var JS = cc.js; var SceneGraphHelper = require('./scene-graph-helper'); -var SGProto = _ccsg.Node.prototype; var Destroying = require('../platform/CCObject').Flags.Destroying; var DirtyFlags = require('./misc').DirtyFlags; @@ -176,7 +175,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ skewX: { - get: SGProto.getSkewX, + get: function () { + return this._skewX; + }, set: function (value) { this._skewX = value; this._sgNode.skewX = value; @@ -189,7 +190,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ skewY: { - get: SGProto.getSkewY, + get: function () { + return this._skewY; + }, set: function (value) { this._skewY = value; this._sgNode._skewY = value; @@ -202,7 +205,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ zIndex: { - get: SGProto.getLocalZOrder, + get: function () { + return this._localZOrder; + }, set: function (value) { this._localZOrder = value; this._sgNode.zIndex = value; @@ -215,7 +220,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ rotation: { - get: SGProto.getRotation, + get: function () { + if (this._rotationX !== this._rotationY) + cc.log(cc._LogInfos.Node.getRotation); + return this._rotationX; + }, set: function (value) { this._rotationX = this._rotationY = value; this._sgNode.rotation = value; @@ -229,7 +238,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ rotationX: { - get: SGProto.getRotationX, + get: function () { + return this._rotationX; + }, set: function (value) { this._rotationX = value; this._sgNode.rotationX = value; @@ -242,7 +253,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ rotationY: { - get: SGProto.getRotationY, + get: function () { + return this._rotationY; + }, set: function (value) { this._rotationY = value; this._sgNode.rotationY = value; @@ -255,7 +268,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ scaleX: { - get: SGProto.getScaleX, + get: function () { + return this._scaleX; + }, set: function (value) { this._scaleX = value; this._sgNode.scaleX = value; @@ -268,7 +283,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ scaleY: { - get: SGProto.getScaleY, + get: function () { + return this._scaleY; + }, set: function (value) { this._scaleY = value; this._sgNode.scaleY = value; @@ -281,7 +298,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ x: { - get: SGProto.getPositionX, + get: function () { + return this._position.x; + }, set: function (value) { this._position.x = value; this._sgNode.x = value; @@ -294,7 +313,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ y: { - get: SGProto.getPositionY, + get: function () { + return this._position.y; + }, set: function (value) { this._position.y = value; this._sgNode.y = value; @@ -331,7 +352,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ anchorX: { - get: SGProto._getAnchorX, + get: function () { + return this._anchorPoint.x; + }, set: function (value) { this._anchorPoint.x = value; this._onAnchorChanged(); @@ -344,7 +367,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Number} */ anchorY: { - get: SGProto._getAnchorY, + get: function () { + return this._anchorPoint.y; + }, set: function (value) { this._anchorPoint.y = value; this._onAnchorChanged(); @@ -406,7 +431,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, //running: { - // get: SGProto.isRunning + // get: //}, /** @@ -415,7 +440,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Boolean} */ ignoreAnchor: { - get: SGProto.isIgnoreAnchorPointForPosition, + get: function () { + return this._ignoreAnchorPointForPosition; + }, set: function (value) { this._ignoreAnchorPointForPosition = value; this._sgNode.ignoreAnchor = value; @@ -461,7 +488,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @type {Boolean} */ cascadeOpacity: { - get: SGProto.isCascadeOpacityEnabled, + get: function () { + return this._cascadeOpacityEnabled; + }, set: function (value) { if (this._cascadeOpacityEnabled !== value) { this._cascadeOpacityEnabled = value; @@ -552,7 +581,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method attr * @param {Object} attrs - Properties to be set to node */ - attr: SGProto.attr, + attr: function (attrs) { + for (var key in attrs) { + this[key] = attrs[key]; + } + }, //Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing. _setLocalZOrder: function (localZOrder) { @@ -586,7 +619,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method getGlobalZOrder * @returns {number} The node's global Z order */ - getGlobalZOrder: SGProto.getGlobalZOrder, + getGlobalZOrder: function () { + return this._globalZOrder; + }, /** * Returns the scale factor of the node. @@ -594,7 +629,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method getScale * @return {Number} The scale factor */ - getScale: SGProto.getScale, + getScale: function () { + if (this._scaleX !== this._scaleY) + cc.log(cc._LogInfos.Node.getScale); + return this._scaleX; + }, /** * Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time. @@ -618,7 +657,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method getPosition * @return {Vec2} The position (x,y) of the node in OpenGL coordinates */ - getPosition: SGProto.getPosition, + getPosition: function () { + return cc.p(this._position); + }, /** *

@@ -658,7 +699,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method getAnchorPoint * @return {Vec2} The anchor point of node. */ - getAnchorPoint: SGProto.getAnchorPoint, + getAnchorPoint: function () { + return cc.p(this._anchorPoint); + }, /** *

@@ -773,7 +816,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ //cc.eventManager.removeListeners(this); // children - SGProto._arrayMakeObjectsPerformSelector(this._children, _ccsg.Node._stateCallbackType.cleanup); + var i, len = this._children.length, node; + for (i = 0; i < len; ++i) { + node = this._children[i]; + if (node) + node.cleanup(); + } }, // composition: GET @@ -784,7 +832,17 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @param {Number} aTag - An identifier to find the child node. * @return {Node} a CCNode object whose tag equals to the input parameter */ - getChildByTag: SGProto.getChildByTag, + getChildByTag: function (aTag) { + var children = this._children; + if (children !== null) { + for (var i = 0; i < children.length; i++) { + var node = children[i]; + if (node && node.tag === aTag) + return node; + } + } + return null; + }, /** * Returns a child from the container given its name @@ -792,7 +850,19 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @param {String} name - A name to find the child node. * @return {Node} a CCNode object whose name equals to the input parameter */ - getChildByName: SGProto.getChildByName, + getChildByName: function(name){ + if(!name){ + cc.log("Invalid name"); + return null; + } + + var locChildren = this._children; + for(var i = 0, len = locChildren.length; i < len; i++){ + if(locChildren[i]._name === name) + return locChildren[i]; + } + return null; + }, // composition: ADD @@ -1058,10 +1128,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ return this._sgNode.getBoundingBoxToWorld(); }, - _getBoundingBoxToCurrentNode: function (parentTransform) { - return this._sgNode._getBoundingBoxToCurrentNode(parentTransform); - }, - /** * Returns the displayed opacity of Node, * the difference between displayed opacity and opacity is that displayed opacity is calculated based on opacity and parent node's opacity when cascade opacity enabled. @@ -1091,15 +1157,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ return this._sgNode.getDisplayedColor(); }, - /** - * Update the displayed color of Node - * @method - * @param {Color} parentColor - */ - _updateDisplayedColor: function (parentColor) { - this._sgNode._updateDisplayedColor(parentColor); - }, - /** * Set whether color should be changed with the opacity value, * useless in ccsg.Node, but this function is override in some class to have such behavior. diff --git a/jsb_polyfill.js b/jsb_polyfill.js new file mode 100644 index 0000000000..dc9b9b20c6 --- /dev/null +++ b/jsb_polyfill.js @@ -0,0 +1,377 @@ + +cc.ParticleSystem.Mode = cc.Enum({ + /** The gravity mode (A mode) */ + GRAVITY: 0, + /** The radius mode (B mode) */ + RADIUS: 1 +}); + +cc.ParticleSystem.Type = cc.Enum({ + /** + * Living particles are attached to the world and are unaffected by emitter repositioning. + */ + FREE: 0, + + /** + * Living particles are attached to the world but will follow the emitter repositioning.
+ * Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite. + */ + RELATIVE: 1, + + /** + * Living particles are attached to the emitter and are translated along with it. + */ + GROUPED: 2 +}); + +cc.ProgressTimer.Type = cc.Enum({ + /** + * Radial Counter-Clockwise + */ + RADIAL: 0, + BAR: 1 +}); + + +cc.EditBox.InputMode = cc.Enum({ + + ANY: 0, + + /** + * The user is allowed to enter an e-mail address. + */ + EMAILADDR: 1, + + /** + * The user is allowed to enter an integer value. + */ + NUMERIC: 2, + + /** + * The user is allowed to enter a phone number. + */ + PHONENUMBER: 3, + + /** + * The user is allowed to enter a URL. + */ + URL: 4, + + /** + * The user is allowed to enter a real number value. + * This extends kEditBoxInputModeNumeric by allowing a decimal point. + */ + DECIMAL: 5, + + /** + * The user is allowed to enter any text, except for line breaks. + */ + SINGLELINE: 6 +}); + +/** + * Enum for the EditBox's input flags + * @readonly + * @enum {number} + * @memberof cc.EditBox + */ +cc.EditBox.InputFlag = cc.Enum({ + /** + * Indicates that the text entered is confidential data that should be + * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. + */ + PASSWORD: 0, + + /** + * Indicates that the text entered is sensitive data that the + * implementation must never store into a dictionary or table for use + * in predictive, auto-completing, or other accelerated input schemes. + * A credit card number is an example of sensitive data. + */ + SENSITIVE: 1, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each word should be capitalized. + */ + INITIAL_CAPS_WORD: 2, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each sentence should be capitalized. + */ + INITIAL_CAPS_SENTENCE: 3, + + /** + * Capitalize all characters automatically. + */ + INITIAL_CAPS_ALL_CHARACTERS: 4 +}); + +/** + * Enum for keyboard return types + * @readonly + * @enum {number} + */ +cc.KeyboardReturnType = cc.Enum({ + DEFAULT: 0, + DONE: 1, + SEND: 2, + SEARCH: 3, + GO: 4 +}); + +/** + * Enum for text alignment + * @readonly + * @enum {number} + */ +cc.TextAlignment = cc.Enum({ + LEFT: 0, + CENTER: 1, + RIGHT: 2 +}); + +/** + * Enum for vertical text alignment + * @readonly + * @enum {number} + */ +cc.VerticalTextAlignment = cc.Enum({ + TOP: 0, + CENTER: 1, + BOTTOM: 2 +}); + +/** + * Enum for Relative layout parameter RelativeAlign + * @readonly + * @enum {number} + */ +ccui.RelativeLayoutParameter.Type = cc.Enum({ + /** + * The none of ccui.RelativeLayoutParameter's relative align. + */ + NONE: 0, + /** + * The parent's top left of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_TOP_LEFT: 1, + /** + * The parent's top center horizontal of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_TOP_CENTER_HORIZONTAL: 2, + /** + * The parent's top right of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_TOP_RIGHT: 3, + /** + * The parent's left center vertical of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_LEFT_CENTER_VERTICAL: 4, + + /** + * The center in parent of ccui.RelativeLayoutParameter's relative align. + */ + CENTER_IN_PARENT: 5, + + /** + * The parent's right center vertical of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_RIGHT_CENTER_VERTICAL: 6, + /** + * The parent's left bottom of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_LEFT_BOTTOM: 7, + /** + * The parent's bottom center horizontal of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_BOTTOM_CENTER_HORIZONTAL: 8, + /** + * The parent's right bottom of ccui.RelativeLayoutParameter's relative align. + */ + PARENT_RIGHT_BOTTOM: 9, + + /** + * The location above left align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_ABOVE_LEFTALIGN: 10, + /** + * The location above center of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_ABOVE_CENTER: 11, + /** + * The location above right align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_ABOVE_RIGHTALIGN: 12, + /** + * The location left of top align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_LEFT_OF_TOPALIGN: 13, + /** + * The location left of center of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_LEFT_OF_CENTER: 14, + /** + * The location left of bottom align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_LEFT_OF_BOTTOMALIGN: 15, + /** + * The location right of top align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_RIGHT_OF_TOPALIGN: 16, + /** + * The location right of center of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_RIGHT_OF_CENTER: 17, + /** + * The location right of bottom align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_RIGHT_OF_BOTTOMALIGN: 18, + /** + * The location below left align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_BELOW_LEFTALIGN: 19, + /** + * The location below center of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_BELOW_CENTER: 20, + /** + * The location below right align of ccui.RelativeLayoutParameter's relative align. + */ + LOCATION_BELOW_RIGHTALIGN: 21 +}); + + +/** + * Enum for layout type + * @readonly + * @enum {number} + */ +ccui.Layout.Type = cc.Enum({ + /** + * The absolute of ccui.Layout's layout type. + */ + ABSOLUTE: 0, + /** + * The vertical of ccui.Layout's layout type. + */ + LINEAR_VERTICAL: 1, + /** + * The horizontal of ccui.Layout's layout type. + */ + LINEAR_HORIZONTAL: 2, + /** + * The relative of ccui.Layout's layout type. + */ + RELATIVE: 3 +}); + +/** + * Enum for loadingBar Type + * @readonly + * @enum {number} + */ +ccui.LoadingBar.Type = cc.Enum({ + /** + * The left direction of ccui.LoadingBar. + */ + LEFT: 0, + /** + * The right direction of ccui.LoadingBar. + */ + RIGHT: 1 +}); + +/** + * Enum for ScrollView direction + * @readonly + * @enum {number} + */ +ccui.ScrollView.Dir = cc.Enum({ + /** + * The none flag of ccui.ScrollView's direction. + */ + NONE: 0, + /** + * The vertical flag of ccui.ScrollView's direction. + */ + VERTICAL: 1, + /** + * The horizontal flag of ccui.ScrollView's direction. + */ + HORIZONTAL: 2, + /** + * The both flag of ccui.ScrollView's direction. + */ + BOTH: 3 +}); + + + +cc.js.mixin(cc.path, { + //todo make public after verification + _normalize: function(url){ + var oldUrl = url = String(url); + + //removing all ../ + do { + oldUrl = url; + url = url.replace(this.normalizeRE, ""); + } while(oldUrl.length !== url.length); + return url; + }, + + // The platform-specific file separator. '\\' or '/'. + sep: (cc.sys.os === cc.sys.OS_WINDOWS ? '\\' : '/'), + + // @param {string} path + // @param {boolean|string} [endsWithSep = true] + // @returns {string} + _setEndWithSep: function (path, endsWithSep) { + var sep = cc.path.sep; + if (typeof endsWithSep === 'undefined') { + endsWithSep = true; + } + else if (typeof endsWithSep === 'string') { + sep = endsWithSep; + endsWithSep = !!endsWithSep; + } + + var endChar = path[path.length - 1]; + var oldEndWithSep = (endChar === '\\' || endChar === '/'); + if (!oldEndWithSep && endsWithSep) { + path += sep; + } + else if (oldEndWithSep && !endsWithSep) { + path = path.slice(0, -1); + } + return path; + } +}); + +cc.EventTarget.call(cc.game); +cc.js.addon(cc.game, cc.EventTarget.prototype); +cc.EventTarget.call(cc.director); +cc.js.addon(cc.director, cc.EventTarget.prototype); + +// cc.Label +cc.Label.Type = cc.Enum({ + TTF: 0, + BMFont: 1 +}); +cc.Label.Overflow = cc.Enum({ + CLAMP: 0, + SHRINK: 1, + RESIZE: 2 +}); + + +// Assets +cc.js.setClassName('cc.SpriteFrame', cc.SpriteFrame); + +// ccsg +window._ccsg = { + Node: cc.Node, + Scene: cc.Scene +}; From 7a1fac062d31d4fa25bf3771ce4f321d55051ca2 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 12 Dec 2015 00:33:27 +0800 Subject: [PATCH 2/3] Fix issues for jsb runtime --- cocos2d/core/CCScene.js | 3 ++ cocos2d/core/components/CCCanvas.js | 4 +- cocos2d/core/components/CCComponentInSG.js | 1 + cocos2d/core/components/CCSpriteRenderer.js | 2 +- cocos2d/core/platform/deserialize.js | 4 ++ cocos2d/core/utils/base-node.js | 52 ++++++++++----------- cocos2d/core/utils/scene-graph-helper.js | 1 + gulpfile.js | 4 +- jsb_polyfill.js | 14 +++++- 9 files changed, 54 insertions(+), 31 deletions(-) diff --git a/cocos2d/core/CCScene.js b/cocos2d/core/CCScene.js index 6160bc2003..66c951d44f 100644 --- a/cocos2d/core/CCScene.js +++ b/cocos2d/core/CCScene.js @@ -37,6 +37,7 @@ cc.Scene = cc.Class({ ctor: function () { var sgNode = this._sgNode = new _ccsg.Scene(); + sgNode.retain(); sgNode.setAnchorPoint(0.0, 0.0); this._anchorPoint.x = 0.0; this._anchorPoint.y = 0.0; @@ -49,6 +50,8 @@ cc.Scene = cc.Class({ var children = this._children; var DontDestroy = cc.Object.Flags.DontDestroy; + this._sgNode.release(); + for (var i = 0, len = children.length; i < len; ++i) { var child = children[i]; if (child.isValid) { diff --git a/cocos2d/core/components/CCCanvas.js b/cocos2d/core/components/CCCanvas.js index 43e69bf397..14c5107897 100644 --- a/cocos2d/core/components/CCCanvas.js +++ b/cocos2d/core/components/CCCanvas.js @@ -145,7 +145,7 @@ var Canvas = cc.Class({ if (CC_EDITOR) { cc.engine.on('design-resolution-changed', this._thisOnResized); } - else { + else if (!cc.sys.isNative) { if (cc.sys.isMobile) { window.addEventListener('resize', this._thisOnResized); } @@ -168,7 +168,7 @@ var Canvas = cc.Class({ if (CC_EDITOR) { cc.engine.off('design-resolution-changed', this._thisOnResized); } - else { + else if (!cc.sys.isNative) { if (cc.sys.isMobile) { window.removeEventListener('resize', this._thisOnResized); } diff --git a/cocos2d/core/components/CCComponentInSG.js b/cocos2d/core/components/CCComponentInSG.js index 91ccf7e3bf..211dbb3a56 100644 --- a/cocos2d/core/components/CCComponentInSG.js +++ b/cocos2d/core/components/CCComponentInSG.js @@ -80,6 +80,7 @@ var ComponentInSG = cc.Class({ sgParent.addChild(sgNode); // retain immediately + // will be released in SceneGraphHelper.removeSgNode sgNode.retain(); this._sgNode = sgNode; } diff --git a/cocos2d/core/components/CCSpriteRenderer.js b/cocos2d/core/components/CCSpriteRenderer.js index 327d4bf803..1d5466e455 100644 --- a/cocos2d/core/components/CCSpriteRenderer.js +++ b/cocos2d/core/components/CCSpriteRenderer.js @@ -460,7 +460,7 @@ var SpriteRenderer = cc.Class({ }, _applySprite: function (sgNode, oldSprite) { - if (oldSprite) { + if (oldSprite && oldSprite.off) { oldSprite.off('load', this._applyCapInset, this); } if (!this._sprite) { return; } diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index 79b36b30b3..0d605f6422 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -414,6 +414,10 @@ var _Deserializer = (function () { else { // instantiate a new object obj = new klass(); + // Temporary solution + if (cc.sys.isNative && klass === cc.SpriteFrame) { + obj.retain(); + } } if (obj._deserialize) { diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index b9b3db7d46..706a0e0a72 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -180,7 +180,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._skewX = value; - this._sgNode.skewX = value; + this._sgNode.setSkewX(value); } }, @@ -195,7 +195,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._skewY = value; - this._sgNode._skewY = value; + this._sgNode.setSkewY(value); } }, @@ -210,7 +210,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._localZOrder = value; - this._sgNode.zIndex = value; + this._sgNode.setLocalZOrder(value); } }, @@ -227,7 +227,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationX = this._rotationY = value; - this._sgNode.rotation = value; + this._sgNode.setRotation(value); }, tooltip: "The clockwise degrees of rotation relative to the parent" }, @@ -243,7 +243,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationX = value; - this._sgNode.rotationX = value; + this._sgNode.setRotationX(value); }, }, @@ -258,7 +258,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationY = value; - this._sgNode.rotationY = value; + this._sgNode.setRotationY(value); }, }, @@ -273,7 +273,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._scaleX = value; - this._sgNode.scaleX = value; + this._sgNode.setScaleX(value); }, }, @@ -288,7 +288,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._scaleY = value; - this._sgNode.scaleY = value; + this._sgNode.setScaleY(value); }, }, @@ -303,7 +303,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._position.x = value; - this._sgNode.x = value; + this._sgNode.setPositionX(value); }, }, @@ -318,7 +318,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._position.y = value; - this._sgNode.y = value; + this._sgNode.setPositionY(value); }, }, @@ -395,7 +395,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ set: function (value) { if (value !== this._contentSize.width) { if (this._sizeProvider) { - this._sizeProvider.setContentSize(new cc.Size(value, this._sizeProvider._getHeight())); + this._sizeProvider.setContentSize(value, this._sizeProvider._getHeight()); } this._contentSize.width = value; this.emit(SIZE_CHANGED); @@ -422,7 +422,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ set: function (value) { if (value !== this._contentSize.height) { if (this._sizeProvider) { - this._sizeProvider.setContentSize(new cc.Size(this._sizeProvider._getWidth(), value)); + this._sizeProvider.setContentSize(this._sizeProvider._getWidth(), value); } this._contentSize.height = value; this.emit(SIZE_CHANGED); @@ -445,7 +445,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._ignoreAnchorPointForPosition = value; - this._sgNode.ignoreAnchor = value; + this._sgNode.ignoreAnchorPointForPosition(value); this._onAnchorChanged(); }, }, @@ -461,7 +461,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._tag = value; - this._sgNode.tag = value; + this._sgNode.setTag(value); }, }, @@ -476,7 +476,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._opacity = value; - this._sgNode.opacity = value; + this._sgNode.setOpacity(value); this._onColorChanged(); }, range: [0, 255] @@ -494,7 +494,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ set: function (value) { if (this._cascadeOpacityEnabled !== value) { this._cascadeOpacityEnabled = value; - this._sgNode.cascadeOpacity = value; + this._sgNode.setCascadeOpacityEnabled(value); this._onCascadeChanged(); } }, @@ -532,8 +532,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }); var sgNode = this._sgNode = new _ccsg.Node(); + sgNode.retain(); if (!cc.game._isCloning) { - sgNode.cascadeOpacity = true; + sgNode.setCascadeOpacityEnabled(true); } this._dirtyFlags = DirtyFlags.ALL; @@ -548,6 +549,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ this._sizeProvider = null; }, + destroy: function () { + this._sgNode.release(); + this._super(); + }, + // ABSTRACT INTERFACES // called when the node's parent changed @@ -587,12 +593,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ } }, - //Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing. - _setLocalZOrder: function (localZOrder) { - this._localZOrder = localZOrder; - this._sgNode._localZOrder = localZOrder; - }, - /** *

Defines the oder in which the nodes are renderer.
* Nodes that have a Global Z Order lower, are renderer first.
@@ -1085,9 +1085,9 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ return this._sgNode.convertToWorldSpaceAR(nodePoint); }, - _convertToWindowSpace: function (nodePoint) { - return this._sgNode._convertToWindowSpace(nodePoint); - }, + // _convertToWindowSpace: function (nodePoint) { + // return this._sgNode._convertToWindowSpace(nodePoint); + // }, /** * convenience methods which take a cc.Touch instead of cc.Vec2 diff --git a/cocos2d/core/utils/scene-graph-helper.js b/cocos2d/core/utils/scene-graph-helper.js index 592517e1d2..fbdfdeb11e 100644 --- a/cocos2d/core/utils/scene-graph-helper.js +++ b/cocos2d/core/utils/scene-graph-helper.js @@ -5,6 +5,7 @@ var SceneGraphUtils = { removeSgNode: function () { var node = this._sgNode; if (node) { + node.release(); if (node._parent) { node._parent.removeChild(node); } diff --git a/gulpfile.js b/gulpfile.js index d07147dcb6..c5d310c741 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -20,7 +20,9 @@ paths = { JSBSkipModules: [ '../../cocos2d/core/CCGame', '../../cocos2d/core/textures/CCTexture2D', - '../../cocos2d/core/sprites/CCSpriteFrame' + '../../cocos2d/core/sprites/CCSpriteFrame', + '../../cocos2d/core/platform/CCLoader', + '../../cocos2d/core/platform/CCLoaders' ], test: { diff --git a/jsb_polyfill.js b/jsb_polyfill.js index dc9b9b20c6..f6ec83772b 100644 --- a/jsb_polyfill.js +++ b/jsb_polyfill.js @@ -1,3 +1,4 @@ +'use strict'; cc.ParticleSystem.Mode = cc.Enum({ /** The gravity mode (A mode) */ @@ -317,7 +318,7 @@ cc.js.mixin(cc.path, { //removing all ../ do { oldUrl = url; - url = url.replace(this.normalizeRE, ""); + url = url.replace(this.normalizeRE, ''); } while(oldUrl.length !== url.length); return url; }, @@ -356,6 +357,17 @@ cc.EventTarget.call(cc.director); cc.js.addon(cc.director, cc.EventTarget.prototype); // cc.Label +cc._Label = cc.Label; +cc.Label = function (string, fontHandle, type) { + var label; + if (type === cc.Label.Type.TTF) { + label = cc._Label.createWithSystemFont(string, fontHandle, 40); + } + else if (type === cc.Label.Type.BMFont) { + label = cc._Label.createWithBMFont(fontHandle, string); + } + return label; +}; cc.Label.Type = cc.Enum({ TTF: 0, BMFont: 1 From a4a051404e9b15665160f6bb5050eab15dcf4f98 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 12 Dec 2015 23:27:10 +0800 Subject: [PATCH 3/3] reverse function invocation to property usage --- cocos2d/core/utils/base-node.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 706a0e0a72..17f363becd 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -180,7 +180,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._skewX = value; - this._sgNode.setSkewX(value); + this._sgNode.skewX = value; } }, @@ -195,7 +195,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._skewY = value; - this._sgNode.setSkewY(value); + this._sgNode.skewY = value; } }, @@ -210,7 +210,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._localZOrder = value; - this._sgNode.setLocalZOrder(value); + this._sgNode.zIndex = value; } }, @@ -227,7 +227,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationX = this._rotationY = value; - this._sgNode.setRotation(value); + this._sgNode.rotation = value; }, tooltip: "The clockwise degrees of rotation relative to the parent" }, @@ -243,7 +243,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationX = value; - this._sgNode.setRotationX(value); + this._sgNode.rotationX = value; }, }, @@ -258,7 +258,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._rotationY = value; - this._sgNode.setRotationY(value); + this._sgNode.rotationY = value; }, }, @@ -273,7 +273,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._scaleX = value; - this._sgNode.setScaleX(value); + this._sgNode.scaleX = value; }, }, @@ -288,7 +288,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._scaleY = value; - this._sgNode.setScaleY(value); + this._sgNode.scaleY = value; }, }, @@ -303,7 +303,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._position.x = value; - this._sgNode.setPositionX(value); + this._sgNode.x = value; }, }, @@ -318,7 +318,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._position.y = value; - this._sgNode.setPositionY(value); + this._sgNode.y = value; }, }, @@ -445,7 +445,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._ignoreAnchorPointForPosition = value; - this._sgNode.ignoreAnchorPointForPosition(value); + this._sgNode.ignoreAnchor = value; this._onAnchorChanged(); }, }, @@ -461,7 +461,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._tag = value; - this._sgNode.setTag(value); + this._sgNode.tag = value; }, }, @@ -476,7 +476,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, set: function (value) { this._opacity = value; - this._sgNode.setOpacity(value); + this._sgNode.opacity = value; this._onColorChanged(); }, range: [0, 255] @@ -494,7 +494,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ set: function (value) { if (this._cascadeOpacityEnabled !== value) { this._cascadeOpacityEnabled = value; - this._sgNode.setCascadeOpacityEnabled(value); + this._sgNode.cascadeOpacity = value; this._onCascadeChanged(); } }, @@ -534,7 +534,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ var sgNode = this._sgNode = new _ccsg.Node(); sgNode.retain(); if (!cc.game._isCloning) { - sgNode.setCascadeOpacityEnabled(true); + sgNode.cascadeOpacity = true; } this._dirtyFlags = DirtyFlags.ALL;