From 7857e84310e560acbf67b1d7801f59765bfdd3ae Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 14 Jan 2014 17:34:12 +0800 Subject: [PATCH 01/24] =?UTF-8?q?Move=20CCFormatHelper=E2=80=99s=20content?= =?UTF-8?q?=20into=20CCFileUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In addition: CCEGLView: Use frame to request full screen instead of canvas --- HelloHTML5World/build.xml | 1 - cocos2d/build.xml | 1 - cocos2d/core/platform/CCEGLView.js | 2 +- cocos2d/core/platform/CCFileUtils.js | 69 +++++++++++++++++ cocos2d/jsloader.js | 1 - cocos2d/particle_nodes/CCFormatHelper.js | 94 ------------------------ template/build.xml | 1 - tools/jsdoc_toolkit/build.xml | 1 - 8 files changed, 70 insertions(+), 100 deletions(-) delete mode 100644 cocos2d/particle_nodes/CCFormatHelper.js diff --git a/HelloHTML5World/build.xml b/HelloHTML5World/build.xml index 368233d8a5..ca2e7fc221 100644 --- a/HelloHTML5World/build.xml +++ b/HelloHTML5World/build.xml @@ -98,7 +98,6 @@ - diff --git a/cocos2d/build.xml b/cocos2d/build.xml index 141377f8bf..a3d68f6f3c 100644 --- a/cocos2d/build.xml +++ b/cocos2d/build.xml @@ -98,7 +98,6 @@ - diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 2ac8dd7f62..6dfba308e7 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -874,7 +874,7 @@ cc.ContainerStrategy = cc.Class.extend({ var frame = view._frame; if (cc.Browser.isMobile && frame == document.documentElement) { // Automatically full screen when user touches on mobile version - cc.Screen.getInstance().autoFullScreen(cc.canvas); + cc.Screen.getInstance().autoFullScreen(frame); } var locCanvasElement = cc.canvas, locContainer = cc.container; diff --git a/cocos2d/core/platform/CCFileUtils.js b/cocos2d/core/platform/CCFileUtils.js index ada7e363af..4dd8d95d07 100644 --- a/cocos2d/core/platform/CCFileUtils.js +++ b/cocos2d/core/platform/CCFileUtils.js @@ -66,6 +66,48 @@ cc.SAX_STRING = 5; */ cc.SAX_ARRAY = 6; +/** + * Image Format:JPG + * @constant + * @type Number + */ +cc.FMT_JPG = 0; + +/** + * Image Format:PNG + * @constant + * @type Number + */ +cc.FMT_PNG = 1; + +/** + * Image Format:TIFF + * @constant + * @type Number + */ +cc.FMT_TIFF = 2; + +/** + * Image Format:RAWDATA + * @constant + * @type Number + */ +cc.FMT_RAWDATA = 3; + +/** + * Image Format:WEBP + * @constant + * @type Number + */ +cc.FMT_WEBP = 4; + +/** + * Image Format:UNKNOWN + * @constant + * @type Number + */ +cc.FMT_UNKNOWN = 5; + //Compatibility with IE9 var Uint8Array = Uint8Array || Array; @@ -808,3 +850,30 @@ cc.FileUtils.getInstance = function () { } return cc.s_SharedFileUtils; }; + +cc.getImageFormatByData = function (imgData) { + // if it is a png file buffer. + if (imgData.length > 8) { + if (imgData[0] == 0x89 + && imgData[1] == 0x50 + && imgData[2] == 0x4E + && imgData[3] == 0x47 + && imgData[4] == 0x0D + && imgData[5] == 0x0A + && imgData[6] == 0x1A + && imgData[7] == 0x0A) { + return cc.FMT_PNG; + } + } + + // if it is a tiff file buffer. + if (imgData.length > 2) { + if ((imgData[0] == 0x49 && imgData[1] == 0x49) + || (imgData[0] == 0x4d && imgData[1] == 0x4d) + || (imgData[0] == 0xff && imgData[1] == 0xd8)) { + return cc.FMT_TIFF; + } + } + + return cc.FMT_UNKNOWN; +}; \ No newline at end of file diff --git a/cocos2d/jsloader.js b/cocos2d/jsloader.js index 3ab47c872c..34ba5f4562 100644 --- a/cocos2d/jsloader.js +++ b/cocos2d/jsloader.js @@ -112,7 +112,6 @@ 'compress/base64.js', 'compress/gzip.js', 'compress/zlib.min.js', - 'particle_nodes/CCFormatHelper.js', 'particle_nodes/CCPNGReader.js', 'particle_nodes/CCTIFFReader.js', 'particle_nodes/CCParticleSystem.js', diff --git a/cocos2d/particle_nodes/CCFormatHelper.js b/cocos2d/particle_nodes/CCFormatHelper.js deleted file mode 100644 index f3dd0622dc..0000000000 --- a/cocos2d/particle_nodes/CCFormatHelper.js +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2014 cocos2d-x.org - - - http://www.cocos2d-x.org - - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -/** - * Image Format:JPG - * @constant - * @type Number - */ -cc.FMT_JPG = 0; - -/** - * Image Format:PNG - * @constant - * @type Number - */ -cc.FMT_PNG = 1; - -/** - * Image Format:TIFF - * @constant - * @type Number - */ -cc.FMT_TIFF = 2; - -/** - * Image Format:RAWDATA - * @constant - * @type Number - */ -cc.FMT_RAWDATA = 3; - -/** - * Image Format:WEBP - * @constant - * @type Number - */ -cc.FMT_WEBP = 4; - -/** - * Image Format:UNKNOWN - * @constant - * @type Number - */ -cc.FMT_UNKNOWN = 5; - -cc.getImageFormatByData = function (imgData) { - // if it is a png file buffer. - if (imgData.length > 8) { - if (imgData[0] == 0x89 - && imgData[1] == 0x50 - && imgData[2] == 0x4E - && imgData[3] == 0x47 - && imgData[4] == 0x0D - && imgData[5] == 0x0A - && imgData[6] == 0x1A - && imgData[7] == 0x0A) { - return cc.FMT_PNG; - } - } - - // if it is a tiff file buffer. - if (imgData.length > 2) { - if ((imgData[0] == 0x49 && imgData[1] == 0x49) - || (imgData[0] == 0x4d && imgData[1] == 0x4d) - || (imgData[0] == 0xff && imgData[1] == 0xd8)) { - return cc.FMT_TIFF; - } - } - - return cc.FMT_UNKNOWN; -}; \ No newline at end of file diff --git a/template/build.xml b/template/build.xml index 0eb25b4127..4e0069cef7 100644 --- a/template/build.xml +++ b/template/build.xml @@ -98,7 +98,6 @@ - diff --git a/tools/jsdoc_toolkit/build.xml b/tools/jsdoc_toolkit/build.xml index b86d0869f0..1c72380baa 100644 --- a/tools/jsdoc_toolkit/build.xml +++ b/tools/jsdoc_toolkit/build.xml @@ -105,7 +105,6 @@ - From 665f59d44e64bc24c302a6c5c5058dd8999c604e Mon Sep 17 00:00:00 2001 From: xingsenma Date: Tue, 14 Jan 2014 17:37:56 +0800 Subject: [PATCH 02/24] closed #3652: armature animation does not display correctly in canvas --- extensions/CocoStudio/Armature/display/CCSkin.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/extensions/CocoStudio/Armature/display/CCSkin.js b/extensions/CocoStudio/Armature/display/CCSkin.js index 998d5fd81d..227bfe221b 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.js +++ b/extensions/CocoStudio/Armature/display/CCSkin.js @@ -33,6 +33,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ _skinTransform:null, _displayName:"", _armature:null, + _skewOver:false, ctor:function () { cc.Sprite.prototype.ctor.call(this); this._skinData = null; @@ -40,6 +41,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ this._displayName = ""; this._skinTransform = cc.AffineTransformIdentity(); this._armature = null; + this._skewOver = false; }, initWithSpriteFrameName:function(spriteFrameName){ var ret = cc.Sprite.prototype.initWithSpriteFrameName.call(this,spriteFrameName); @@ -60,6 +62,13 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ this.setRotationY(cc.RADIANS_TO_DEGREES(-skinData.skewY)); this.setPosition(skinData.x, skinData.y); + if (!cc.Browser.supportWebGL) { + if (skinData.skewX != -skinData.skewY) { + this._skewOver = true; + this.nodeToParentTransform = cc.Node.prototype._nodeToParentTransformForWebGL; + } + } + var localTransform = this.nodeToParentTransform(); var skinTransform = this._skinTransform; skinTransform.a = localTransform.a; @@ -86,6 +95,12 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ updateArmatureTransform:function () { this._transform = cc.AffineTransformConcat(this._skinTransform, this._bone.nodeToArmatureTransform()); var locTransform = this._transform; + + if (this._skewOver) { + locTransform.b *= -1; + locTransform.c *= -1; + } + var locArmature = this._armature; if (locArmature && locArmature.getBatchNode()) { this._transform = cc.AffineTransformConcat(locTransform, locTransform.nodeToParentTransform()); From 3dc3f19a00b0a0ff1821b0b97843079f143066fc Mon Sep 17 00:00:00 2001 From: xingsenma Date: Tue, 14 Jan 2014 17:45:31 +0800 Subject: [PATCH 03/24] issue #3652: armature animation does not display correctly in canvas --- extensions/CocoStudio/Armature/display/CCSkin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/CocoStudio/Armature/display/CCSkin.js b/extensions/CocoStudio/Armature/display/CCSkin.js index 227bfe221b..917da3bd0f 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.js +++ b/extensions/CocoStudio/Armature/display/CCSkin.js @@ -62,7 +62,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ this.setRotationY(cc.RADIANS_TO_DEGREES(-skinData.skewY)); this.setPosition(skinData.x, skinData.y); - if (!cc.Browser.supportWebGL) { + if (cc.renderContextType === cc.CANVAS) { if (skinData.skewX != -skinData.skewY) { this._skewOver = true; this.nodeToParentTransform = cc.Node.prototype._nodeToParentTransformForWebGL; From bfb2f963681d29c08815c219bdf6e908233c3da2 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 14 Jan 2014 17:52:54 +0800 Subject: [PATCH 04/24] Refactor #3690: Move CCNS.js content into CCCommon.js --- HelloHTML5World/build.xml | 1 - cocos2d/build.xml | 1 - cocos2d/core/cocoa/CCNS.js | 85 ----------------- cocos2d/core/platform/CCCommon.js | 133 +++++++++++++++++++++++++++ cocos2d/core/platform/CCFileUtils.js | 69 -------------- cocos2d/jsloader.js | 1 - template/build.xml | 1 - tools/jsdoc_toolkit/build.xml | 1 - 8 files changed, 133 insertions(+), 159 deletions(-) delete mode 100644 cocos2d/core/cocoa/CCNS.js diff --git a/HelloHTML5World/build.xml b/HelloHTML5World/build.xml index ca2e7fc221..a17bfbc957 100644 --- a/HelloHTML5World/build.xml +++ b/HelloHTML5World/build.xml @@ -25,7 +25,6 @@ - diff --git a/cocos2d/build.xml b/cocos2d/build.xml index a3d68f6f3c..09c48eda4f 100644 --- a/cocos2d/build.xml +++ b/cocos2d/build.xml @@ -25,7 +25,6 @@ - diff --git a/cocos2d/core/cocoa/CCNS.js b/cocos2d/core/cocoa/CCNS.js deleted file mode 100644 index aa07f67416..0000000000 --- a/cocos2d/core/cocoa/CCNS.js +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011 Zynga Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -var CCNS_REG1 = /^\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*$/; -var CCNS_REG2 = /^\s*\{\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*,\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*\}\s*$/ -/** - * Returns a Core Graphics rectangle structure corresponding to the data in a given string.
- * The string is not localized, so items are always separated with a comma.
- * If the string is not well-formed, the function returns cc.RectZero. - * @function - * @param {String} content content A string object whose contents are of the form "{{x,y},{w, h}}",
- * where x is the x coordinate, y is the y coordinate, w is the width, and h is the height.
- * These components can represent integer or float values. - * @return {cc.Rect} A Core Graphics structure that represents a rectangle. - * Constructor - * @example - * // example - * var rect = cc.RectFromString("{{3,2},{4,5}}"); - */ -cc.RectFromString = function (content) { - var result = CCNS_REG2.exec(content); - if(!result) return cc.RectZero(); - return cc.rect(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3]), parseFloat(result[4])); -}; - -/** - * Returns a Core Graphics point structure corresponding to the data in a given string. - * @function - * @param {String} content A string object whose contents are of the form "{x,y}", - * where x is the x coordinate and y is the y coordinate.
- * The x and y values can represent integer or float values.
- * The string is not localized, so items are always separated with a comma.
- * @return {cc.Point} A Core Graphics structure that represents a point.
- * If the string is not well-formed, the function returns cc.PointZero. - * Constructor - * @example - * //example - * var point = cc.PointFromString("{3.0,2.5}"); - */ -cc.PointFromString = function (content) { - var result = CCNS_REG1.exec(content); - if(!result) return cc.PointZero(); - return cc.p(parseFloat(result[1]), parseFloat(result[2])); -}; - -/** - * Returns a Core Graphics size structure corresponding to the data in a given string. - * @function - * @param {String} content A string object whose contents are of the form "{w, h}",
- * where w is the width and h is the height.
- * The w and h values can be integer or float values.
- * The string is not localized, so items are always separated with a comma.
- * @return {cc.Size} A Core Graphics structure that represents a size.
- * If the string is not well-formed, the function returns cc.SizeZero. - * @example - * // example - * var size = cc.SizeFromString("{3.0,2.5}"); - */ -cc.SizeFromString = function (content) { - var result = CCNS_REG1.exec(content); - if(!result) return cc.SizeZero(); - return cc.size(parseFloat(result[1]), parseFloat(result[2])); -}; \ No newline at end of file diff --git a/cocos2d/core/platform/CCCommon.js b/cocos2d/core/platform/CCCommon.js index 53d96b8403..3814fc3a64 100644 --- a/cocos2d/core/platform/CCCommon.js +++ b/cocos2d/core/platform/CCCommon.js @@ -422,3 +422,136 @@ cc.KEY = { quote:222, space:32 }; + + +/** + * Image Format:JPG + * @constant + * @type Number + */ +cc.FMT_JPG = 0; + +/** + * Image Format:PNG + * @constant + * @type Number + */ +cc.FMT_PNG = 1; + +/** + * Image Format:TIFF + * @constant + * @type Number + */ +cc.FMT_TIFF = 2; + +/** + * Image Format:RAWDATA + * @constant + * @type Number + */ +cc.FMT_RAWDATA = 3; + +/** + * Image Format:WEBP + * @constant + * @type Number + */ +cc.FMT_WEBP = 4; + +/** + * Image Format:UNKNOWN + * @constant + * @type Number + */ +cc.FMT_UNKNOWN = 5; + +cc.getImageFormatByData = function (imgData) { + // if it is a png file buffer. + if (imgData.length > 8) { + if (imgData[0] == 0x89 + && imgData[1] == 0x50 + && imgData[2] == 0x4E + && imgData[3] == 0x47 + && imgData[4] == 0x0D + && imgData[5] == 0x0A + && imgData[6] == 0x1A + && imgData[7] == 0x0A) { + return cc.FMT_PNG; + } + } + + // if it is a tiff file buffer. + if (imgData.length > 2) { + if ((imgData[0] == 0x49 && imgData[1] == 0x49) + || (imgData[0] == 0x4d && imgData[1] == 0x4d) + || (imgData[0] == 0xff && imgData[1] == 0xd8)) { + return cc.FMT_TIFF; + } + } + + return cc.FMT_UNKNOWN; +}; + + + +var CCNS_REG1 = /^\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*$/; +var CCNS_REG2 = /^\s*\{\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*,\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*\}\s*$/ +/** + * Returns a Core Graphics rectangle structure corresponding to the data in a given string.
+ * The string is not localized, so items are always separated with a comma.
+ * If the string is not well-formed, the function returns cc.RectZero. + * @function + * @param {String} content content A string object whose contents are of the form "{{x,y},{w, h}}",
+ * where x is the x coordinate, y is the y coordinate, w is the width, and h is the height.
+ * These components can represent integer or float values. + * @return {cc.Rect} A Core Graphics structure that represents a rectangle. + * Constructor + * @example + * // example + * var rect = cc.RectFromString("{{3,2},{4,5}}"); + */ +cc.RectFromString = function (content) { + var result = CCNS_REG2.exec(content); + if(!result) return cc.RectZero(); + return cc.rect(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3]), parseFloat(result[4])); +}; + +/** + * Returns a Core Graphics point structure corresponding to the data in a given string. + * @function + * @param {String} content A string object whose contents are of the form "{x,y}", + * where x is the x coordinate and y is the y coordinate.
+ * The x and y values can represent integer or float values.
+ * The string is not localized, so items are always separated with a comma.
+ * @return {cc.Point} A Core Graphics structure that represents a point.
+ * If the string is not well-formed, the function returns cc.PointZero. + * Constructor + * @example + * //example + * var point = cc.PointFromString("{3.0,2.5}"); + */ +cc.PointFromString = function (content) { + var result = CCNS_REG1.exec(content); + if(!result) return cc.PointZero(); + return cc.p(parseFloat(result[1]), parseFloat(result[2])); +}; + +/** + * Returns a Core Graphics size structure corresponding to the data in a given string. + * @function + * @param {String} content A string object whose contents are of the form "{w, h}",
+ * where w is the width and h is the height.
+ * The w and h values can be integer or float values.
+ * The string is not localized, so items are always separated with a comma.
+ * @return {cc.Size} A Core Graphics structure that represents a size.
+ * If the string is not well-formed, the function returns cc.SizeZero. + * @example + * // example + * var size = cc.SizeFromString("{3.0,2.5}"); + */ +cc.SizeFromString = function (content) { + var result = CCNS_REG1.exec(content); + if(!result) return cc.SizeZero(); + return cc.size(parseFloat(result[1]), parseFloat(result[2])); +}; \ No newline at end of file diff --git a/cocos2d/core/platform/CCFileUtils.js b/cocos2d/core/platform/CCFileUtils.js index 4dd8d95d07..6a57626966 100644 --- a/cocos2d/core/platform/CCFileUtils.js +++ b/cocos2d/core/platform/CCFileUtils.js @@ -66,48 +66,6 @@ cc.SAX_STRING = 5; */ cc.SAX_ARRAY = 6; -/** - * Image Format:JPG - * @constant - * @type Number - */ -cc.FMT_JPG = 0; - -/** - * Image Format:PNG - * @constant - * @type Number - */ -cc.FMT_PNG = 1; - -/** - * Image Format:TIFF - * @constant - * @type Number - */ -cc.FMT_TIFF = 2; - -/** - * Image Format:RAWDATA - * @constant - * @type Number - */ -cc.FMT_RAWDATA = 3; - -/** - * Image Format:WEBP - * @constant - * @type Number - */ -cc.FMT_WEBP = 4; - -/** - * Image Format:UNKNOWN - * @constant - * @type Number - */ -cc.FMT_UNKNOWN = 5; - //Compatibility with IE9 var Uint8Array = Uint8Array || Array; @@ -849,31 +807,4 @@ cc.FileUtils.getInstance = function () { cc.s_SharedFileUtils = new cc.FileUtils(); } return cc.s_SharedFileUtils; -}; - -cc.getImageFormatByData = function (imgData) { - // if it is a png file buffer. - if (imgData.length > 8) { - if (imgData[0] == 0x89 - && imgData[1] == 0x50 - && imgData[2] == 0x4E - && imgData[3] == 0x47 - && imgData[4] == 0x0D - && imgData[5] == 0x0A - && imgData[6] == 0x1A - && imgData[7] == 0x0A) { - return cc.FMT_PNG; - } - } - - // if it is a tiff file buffer. - if (imgData.length > 2) { - if ((imgData[0] == 0x49 && imgData[1] == 0x49) - || (imgData[0] == 0x4d && imgData[1] == 0x4d) - || (imgData[0] == 0xff && imgData[1] == 0xd8)) { - return cc.FMT_TIFF; - } - } - - return cc.FMT_UNKNOWN; }; \ No newline at end of file diff --git a/cocos2d/jsloader.js b/cocos2d/jsloader.js index 34ba5f4562..08b15bc9b4 100644 --- a/cocos2d/jsloader.js +++ b/cocos2d/jsloader.js @@ -39,7 +39,6 @@ 'core/platform/CCEGLView.js', 'core/platform/CCScreen.js', 'core/platform/CCVisibleRect.js', - 'core/cocoa/CCNS.js', 'core/cocoa/CCAffineTransform.js', 'core/support/CCPointExtension.js', 'core/support/CCVertex.js', diff --git a/template/build.xml b/template/build.xml index 4e0069cef7..d5dbc42606 100644 --- a/template/build.xml +++ b/template/build.xml @@ -25,7 +25,6 @@ - diff --git a/tools/jsdoc_toolkit/build.xml b/tools/jsdoc_toolkit/build.xml index 1c72380baa..23b60bcb1e 100644 --- a/tools/jsdoc_toolkit/build.xml +++ b/tools/jsdoc_toolkit/build.xml @@ -32,7 +32,6 @@ - From 8eb3cdd0184e2b0b9717418410216b3f2abf4e06 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 15 Jan 2014 14:27:04 +0800 Subject: [PATCH 05/24] =?UTF-8?q?Fixed=20#3709:=20Refactored=20cc.Screen?= =?UTF-8?q?=20to=20support=20all=20browsers=20Tested=20on=20Safari=20/=20C?= =?UTF-8?q?hrome=20/=20Firefox=20/=20Opera,=20firefox=20and=20opera=20does?= =?UTF-8?q?n=E2=80=99t=20take=20count=20of=20exitFullscreen=20function,=20?= =?UTF-8?q?all=20other=20functionalities=20works=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/platform/CCScreen.js | 108 ++++++++++++++++++------------ samples | 2 +- 2 files changed, 68 insertions(+), 42 deletions(-) diff --git a/cocos2d/core/platform/CCScreen.js b/cocos2d/core/platform/CCScreen.js index 1cfdf7de04..00a24da04d 100644 --- a/cocos2d/core/platform/CCScreen.js +++ b/cocos2d/core/platform/CCScreen.js @@ -32,26 +32,56 @@ */ cc.Screen = cc.Class.extend({ _supportsFullScreen: false, - _browserPrefix: "", - _preElement: null,//the pre element to show in full screen mode. - _preOnFullScreenChange: null,//the pre fullscreenchange function + // the pre fullscreenchange function + _preOnFullScreenChange: null, _touchEvent: "", + _fn: null, + // Function mapping for cross browser support + _fnMap: [ + [ + 'requestFullscreen', + 'exitFullscreen', + 'fullscreenchange', + 'fullscreenEnabled', + 'fullscreenElement' + ], + [ + 'webkitRequestFullScreen', + 'webkitCancelFullScreen', + 'webkitfullscreenchange', + 'webkitIsFullScreen', + 'webkitCurrentFullScreenElement' + ], + [ + 'mozRequestFullScreen', + 'mozCancelFullScreen', + 'mozfullscreenchange', + 'mozFullScreen', + 'mozFullScreenElement' + ], + [ + 'msRequestFullscreen', + 'msExitFullscreen', + 'MSFullscreenChange', + 'msFullscreenEnabled', + 'msFullscreenElement' + ] + ], + init: function () { - var browserPres = 'webkit,moz,o,ms,khtml'.split(','); - var body = document.body; - if (body["requestFullScreen"]) { - this._supportsFullScreen = true; - } else { - for (var i = 0, il = browserPres.length, prefix; i < il; i++) { - prefix = browserPres[i]; - if (body[prefix + "RequestFullScreen"]) { - this._supportsFullScreen = true; - this._browserPrefix = prefix; - break; - } - } - } + this._fn = {}; + var i, val, map = this._fnMap, valL; + for (i = 0, l = map.length; i < l; i++ ) { + val = map[ i ]; + if ( val && val[1] in document ) { + for ( i = 0, valL = val.length; i < valL; i++ ) { + this._fn[ map[0][ i ] ] = val[ i ]; + } + break; + } + } + this._supportsFullScreen = (this._fn.requestFullscreen != undefined); this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown'; }, @@ -59,19 +89,8 @@ cc.Screen = cc.Class.extend({ * return true if it's full now. * @returns {Boolean} */ - fullScreen: function () { - var d = document; - if (this._supportsFullScreen) { - switch (this._browserPrefix) { - case '': - return d["fullScreen"]; - case 'webkit': - return d["webkitIsFullScreen"]; - default: - return d[this._browserPrefix + 'FullScreen']; - } - } - return false; + fullScreen: function() { + return this._supportsFullScreen && document[ this._fn.fullscreenEnabled ]; }, /** @@ -81,15 +100,20 @@ cc.Screen = cc.Class.extend({ * @returns {*} */ requestFullScreen: function (element, onFullScreenChange) { - if (!this._supportsFullScreen || this.fullScreen()) return; - if (onFullScreenChange) { - var eventName = this._browserPrefix + "fullscreenchange"; - if (this._preElement && this._preOnFullScreenChange) this._preElement.removeEventListener(eventName, this._preOnFullScreenChange); - this._preElement = element; - this._preOnFullScreenChange = onFullScreenChange; - element.addEventListener(eventName, onFullScreenChange, false); - } - return (this._browserPrefix === '') ? element["requestFullScreen"]() : element[this._browserPrefix + 'RequestFullScreen'](); + if (!this._supportsFullScreen) return; + + element = element || document.documentElement; + element[ this._fn.requestFullscreen ](); + + if (onFullScreenChange) { + var eventName = this._fn.fullscreenchange; + if (this._preOnFullScreenChange) + document.removeEventListener(eventName, this._preOnFullScreenChange); + this._preOnFullScreenChange = onFullScreenChange; + document.addEventListener(eventName, onFullScreenChange, false); + } + + return element[ this._fn.requestFullscreen ](); }, /** @@ -97,14 +121,16 @@ cc.Screen = cc.Class.extend({ * @returns {*} */ exitFullScreen: function () { - if (!this._supportsFullScreen || !this.fullScreen()) return; - return (this._browserPrefix === '') ? document.body["cancelFullScreen"]() : document.body[this._browserPrefix + 'CancelFullScreen'](); + return this._supportsFullScreen ? document[ this._fn.exitFullscreen ]() : true; }, /** * Automatically request full screen with a touch/click event + * @param {Element} element + * @param {Function} onFullScreenChange */ autoFullScreen: function (element, onFullScreenChange) { + element = element || document.body; var theScreen = this; // Function bind will be too complicated here because we need the callback function's reference to remove the listener function callback() { diff --git a/samples b/samples index 934798112f..02a289a5f6 160000 --- a/samples +++ b/samples @@ -1 +1 @@ -Subproject commit 934798112f9f81fd90f118baa8f0bcc01bc74d9c +Subproject commit 02a289a5f6615f36ce0436ffe0cd6188bc433b5d From 6f507baf31a92ed1a0e4403950e2b4b8dd8f038d Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 16 Jan 2014 14:54:58 +0800 Subject: [PATCH 06/24] issue #3652: correct explain for ccs.Widget --- extensions/CocoStudio/GUI/BaseClasses/UIWidget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js b/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js index bbb923b85d..92bad74c8e 100644 --- a/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js +++ b/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js @@ -86,7 +86,7 @@ ccs.PositionType = { * var uiLayer = ccs.UILayer.create(); * uiLayer.addWidget(uiWidget); * @class - * @extends ccs.Class + * @extends ccs.NodeRGBA */ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{ _enabled: true, ///< Highest control of widget From fb14eef0cdee83c53521c8571f6290365d98295c Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 16 Jan 2014 14:56:42 +0800 Subject: [PATCH 07/24] issue #3652: correct the super of visit for ccs.Layout --- extensions/CocoStudio/GUI/Layouts/UILayout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/CocoStudio/GUI/Layouts/UILayout.js b/extensions/CocoStudio/GUI/Layouts/UILayout.js index 6057efb392..32a4f52131 100644 --- a/extensions/CocoStudio/GUI/Layouts/UILayout.js +++ b/extensions/CocoStudio/GUI/Layouts/UILayout.js @@ -380,7 +380,7 @@ ccs.Layout = ccs.Widget.extend(/** @lends ccs.Layout# */{ context.save(); // Draw everything first using node visit function - this._super(context); + cc.Node.prototype.visit.call(this, context); context.globalCompositeOperation = "destination-in"; From 765cb29843c3710631c2135d41ba98a3594fb616 Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 16 Jan 2014 14:57:50 +0800 Subject: [PATCH 08/24] issue #3652: add convert string for setText --- extensions/CocoStudio/GUI/UIWidgets/UITextField.js | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/CocoStudio/GUI/UIWidgets/UITextField.js b/extensions/CocoStudio/GUI/UIWidgets/UITextField.js index ccaf9bc692..96fec6286e 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/UITextField.js +++ b/extensions/CocoStudio/GUI/UIWidgets/UITextField.js @@ -300,6 +300,7 @@ ccs.TextField = ccs.Widget.extend(/** @lends ccs.TextField# */{ if (!text) { return; } + text = String(text); if (this.isMaxLengthEnabled()) { text = text.substr(0, this.getMaxLength()); } From 01adb75d7fd917a86eb3c74337e2d616d89707fe Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 16 Jan 2014 14:58:46 +0800 Subject: [PATCH 09/24] closed #3652: armature animation does not display correctly in canvas --- .../CocoStudio/Armature/animation/CCTween.js | 5 ++-- .../Armature/display/CCDisplayFactory.js | 4 --- .../CocoStudio/Armature/display/CCSkin.js | 27 +++++++------------ .../Armature/physics/CCColliderDetector.js | 23 +++++++++------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/extensions/CocoStudio/Armature/animation/CCTween.js b/extensions/CocoStudio/Armature/animation/CCTween.js index e749ab8605..b6a40f89cb 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.js +++ b/extensions/CocoStudio/Armature/animation/CCTween.js @@ -269,11 +269,12 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ var displayManager = locBone.getDisplayManager(); if (!displayManager.getForceChangeDisplay()) { displayManager.changeDisplayWithIndex(displayIndex, false); - + var locRenderNode = displayManager.getDisplayRenderNode(); + if(locRenderNode) + locRenderNode.setBlendFunc(keyFrameData.blendFunc); } this._tweenData.zOrder = keyFrameData.zOrder; locBone.updateZOrder(); - locBone.setBlendFunc(keyFrameData.blendFunc); var childAramture = locBone.getChildArmature(); if (childAramture) { if (keyFrameData.movement != "") { diff --git a/extensions/CocoStudio/Armature/display/CCDisplayFactory.js b/extensions/CocoStudio/Armature/display/CCDisplayFactory.js index aff3bed8b9..4c6f9421b9 100644 --- a/extensions/CocoStudio/Armature/display/CCDisplayFactory.js +++ b/extensions/CocoStudio/Armature/display/CCDisplayFactory.js @@ -62,10 +62,6 @@ ccs.DisplayFactory.updateDisplay = function (bone,dt, dirty) { switch (bone.getDisplayRenderNodeType()) { case ccs.DisplayType.sprite: if (dirty){ - if(bone.isBlendDirty()){ - display.setBlendFunc(bone.getBlendFunc()); - bone.setBlendDirty(false); - } display.updateArmatureTransform(); } break; diff --git a/extensions/CocoStudio/Armature/display/CCSkin.js b/extensions/CocoStudio/Armature/display/CCSkin.js index 917da3bd0f..4081a780fd 100644 --- a/extensions/CocoStudio/Armature/display/CCSkin.js +++ b/extensions/CocoStudio/Armature/display/CCSkin.js @@ -33,7 +33,6 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ _skinTransform:null, _displayName:"", _armature:null, - _skewOver:false, ctor:function () { cc.Sprite.prototype.ctor.call(this); this._skinData = null; @@ -41,7 +40,6 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ this._displayName = ""; this._skinTransform = cc.AffineTransformIdentity(); this._armature = null; - this._skewOver = false; }, initWithSpriteFrameName:function(spriteFrameName){ var ret = cc.Sprite.prototype.initWithSpriteFrameName.call(this,spriteFrameName); @@ -62,13 +60,6 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ this.setRotationY(cc.RADIANS_TO_DEGREES(-skinData.skewY)); this.setPosition(skinData.x, skinData.y); - if (cc.renderContextType === cc.CANVAS) { - if (skinData.skewX != -skinData.skewY) { - this._skewOver = true; - this.nodeToParentTransform = cc.Node.prototype._nodeToParentTransformForWebGL; - } - } - var localTransform = this.nodeToParentTransform(); var skinTransform = this._skinTransform; skinTransform.a = localTransform.a; @@ -95,15 +86,17 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ updateArmatureTransform:function () { this._transform = cc.AffineTransformConcat(this._skinTransform, this._bone.nodeToArmatureTransform()); var locTransform = this._transform; - - if (this._skewOver) { - locTransform.b *= -1; - locTransform.c *= -1; - } - var locArmature = this._armature; if (locArmature && locArmature.getBatchNode()) { - this._transform = cc.AffineTransformConcat(locTransform, locTransform.nodeToParentTransform()); + this._transform = cc.AffineTransformConcat(locTransform, locArmature.nodeToParentTransform()); + } + if (cc.renderContextType === cc.CANVAS) { + locTransform = this._transform + locTransform.b *= -1; + locTransform.c *= -1; + var tempB = locTransform.b; + locTransform.b = locTransform.c; + locTransform.c = tempB; } }, /** returns a "local" axis aligned bounding box of the node.
@@ -140,7 +133,7 @@ ccs.Skin = ccs.Sprite.extend(/** @lends ccs.Skin# */{ return cc.AffineTransformConcat(displayTransform, this._bone.getArmature().nodeToWorldTransform()); } }); - +ccs.Skin.prototype.nodeToParentTransform = cc.Node.prototype._nodeToParentTransformForWebGL; /** * allocates and initializes a skin. * @param {String} fileName diff --git a/extensions/CocoStudio/Armature/physics/CCColliderDetector.js b/extensions/CocoStudio/Armature/physics/CCColliderDetector.js index 0a6cdddbea..7cb8de35e1 100644 --- a/extensions/CocoStudio/Armature/physics/CCColliderDetector.js +++ b/extensions/CocoStudio/Armature/physics/CCColliderDetector.js @@ -258,25 +258,30 @@ ccs.ColliderDetector = ccs.Class.extend(/** @lends ccs.ColliderDetector# */{ var shape = null; if (locBody) { shape = colliderBody.getShape(); - locBody.p.x = t.tx; - locBody.p.y = t.ty; - locBody.p.a = t.a; } var vs = contourData.vertexList; var cvs = colliderBody.getCalculatedVertexList(); - for (var i = 0; i < vs.length; i++) { - locHelpPoint.x = vs[i].x; - locHelpPoint.y = vs[i].y; + for (var j = 0; j < vs.length; j++) { + locHelpPoint.x = vs[j].x; + locHelpPoint.y = vs[j].y; locHelpPoint = cc.PointApplyAffineTransform(locHelpPoint, t); if (shape) { - shape.verts[i * 2] = locHelpPoint.x - t.tx; - shape.verts[i * 2 + 1] = locHelpPoint.y - t.ty; + shape.verts[j * 2] = locHelpPoint.x; + shape.verts[j * 2 + 1] = locHelpPoint.y; } if (ccs.ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX) { var v = cc.p(0, 0); v.x = locHelpPoint.x; v.y = locHelpPoint.y; - cvs[i] = v; + cvs[j] = v; + } + } + if (shape) { + for (var j = 0; j < vs.length; j++) { + var b = shape.verts[(j + 1) % shape.verts.length]; + var n = cp.v.normalize(cp.v.perp(cp.v.sub(b, shape.verts[j]))); + shape.axes[j].n = n; + shape.axes[j].d = cp.v.dot(n, shape.verts[j]); } } } From d5ebed61e12efa271c89b2aadf9d2b5ec5c8646c Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 16 Jan 2014 18:18:58 +0800 Subject: [PATCH 10/24] issue #3731: Fix bugs of clone gui widget --- .../CocoStudio/GUI/BaseClasses/UIWidget.js | 5 ++++ extensions/CocoStudio/GUI/Layouts/UILayout.js | 12 ++++++--- .../GUI/Layouts/UILayoutParameter.js | 27 ++++++++++++++++++- .../CocoStudio/GUI/UIWidgets/UIButton.js | 4 ++- .../CocoStudio/GUI/UIWidgets/UILabel.js | 6 ++--- .../CocoStudio/GUI/UIWidgets/UILoadingBar.js | 1 + 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js b/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js index 92bad74c8e..ffeb100bd1 100644 --- a/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js +++ b/extensions/CocoStudio/GUI/BaseClasses/UIWidget.js @@ -1221,6 +1221,11 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{ this.setOpacity(widget.getOpacity()); this.setCascadeOpacityEnabled(widget.isCascadeOpacityEnabled()); this.setCascadeColorEnabled(widget.isCascadeColorEnabled()); + for (var key in widget._layoutParameterDictionary) { + var parameter = widget._layoutParameterDictionary[key]; + if (parameter) + this.setLayoutParameter(parameter.clone()); + } this.onSizeChanged(); }, diff --git a/extensions/CocoStudio/GUI/Layouts/UILayout.js b/extensions/CocoStudio/GUI/Layouts/UILayout.js index 32a4f52131..6162bbc051 100644 --- a/extensions/CocoStudio/GUI/Layouts/UILayout.js +++ b/extensions/CocoStudio/GUI/Layouts/UILayout.js @@ -784,12 +784,17 @@ ccs.Layout = ccs.Widget.extend(/** @lends ccs.Layout# */{ */ setBackGroundColor: function (color, endColor) { if (!endColor) { - this._color = color; + this._color.r = color.r; + this._color.g = color.g; + this._color.b = color.b; if (this._colorRender) { this._colorRender.setColor(color); } } else { - this._startColor = color; + this._startColor.r = color.r; + this._startColor.g = color.g; + this._startColor.b = color.b; + if (this._gradientRender) { this._gradientRender.setStartColor(color); } @@ -825,7 +830,8 @@ ccs.Layout = ccs.Widget.extend(/** @lends ccs.Layout# */{ * @param {cc.Point} vector */ setBackGroundColorVector: function (vector) { - this._alongVector = vector; + this._alongVector.x = vector.x; + this._alongVector.y = vector.y; if (this._gradientRender) { this._gradientRender.setVector(vector); } diff --git a/extensions/CocoStudio/GUI/Layouts/UILayoutParameter.js b/extensions/CocoStudio/GUI/Layouts/UILayoutParameter.js index 86be66b46e..17a8864cb6 100644 --- a/extensions/CocoStudio/GUI/Layouts/UILayoutParameter.js +++ b/extensions/CocoStudio/GUI/Layouts/UILayoutParameter.js @@ -50,7 +50,10 @@ ccs.LayoutParameter = ccs.Class.extend(/** @lends ccs.LayoutParameter# */{ * @param {ccs.Margin} margin */ setMargin: function (margin) { - this._margin = margin; + this._margin.left = margin.left; + this._margin.top = margin.top; + this._margin.right = margin.right; + this._margin.bottom = margin.bottom; }, /** @@ -67,6 +70,12 @@ ccs.LayoutParameter = ccs.Class.extend(/** @lends ccs.LayoutParameter# */{ */ getLayoutType: function () { return this._layoutParameterType; + }, + + clone:function(){ + var parameter = new ccs.LayoutParameter(); + parameter.setMargin(this._margin); + return parameter; } }); @@ -110,6 +119,13 @@ ccs.LinearLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.LinearLayo */ getGravity: function () { return this._linearGravity; + }, + + clone:function(){ + var parameter = new ccs.LinearLayoutParameter(); + parameter.setMargin(this._margin); + parameter.setGravity(this._linearGravity); + return parameter; } }); @@ -191,6 +207,15 @@ ccs.RelativeLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.Relative */ getRelativeName: function () { return this._relativeLayoutName; + }, + + clone:function(){ + var parameter = new ccs.RelativeLayoutParameter(); + parameter.setMargin(this._margin); + parameter.setAlign(this._relativeAlign); + parameter.setRelativeToWidgetName(this._relativeWidgetName); + parameter.setRelativeName(this._relativeLayoutName); + return parameter; } }); diff --git a/extensions/CocoStudio/GUI/UIWidgets/UIButton.js b/extensions/CocoStudio/GUI/UIWidgets/UIButton.js index 042b6cc08b..2a819c0e92 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/UIButton.js +++ b/extensions/CocoStudio/GUI/UIWidgets/UIButton.js @@ -646,7 +646,9 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ * @param {cc.c3b} color */ setTitleColor: function (color) { - this._titleColor = color; + this._titleColor.r = color.r; + this._titleColor.g = color.g; + this._titleColor.b = color.b; this._titleRenderer.updateDisplayedColor(color); }, diff --git a/extensions/CocoStudio/GUI/UIWidgets/UILabel.js b/extensions/CocoStudio/GUI/UIWidgets/UILabel.js index 13aa51c568..e9f2bb63d8 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/UILabel.js +++ b/extensions/CocoStudio/GUI/UIWidgets/UILabel.js @@ -164,8 +164,8 @@ ccs.Label = ccs.Widget.extend(/** @lends ccs.Label# */{ */ setTouchScaleChangeEnabled: function (enable) { this._touchScaleChangeEnabled = enable; - this._normalScaleValueX = this.getScaleX(); - this._normalScaleValueY = this.getScaleY(); + //this._normalScaleValueX = this.getScaleX(); + //this._normalScaleValueY = this.getScaleY(); }, /** @@ -187,7 +187,7 @@ ccs.Label = ccs.Widget.extend(/** @lends ccs.Label# */{ if (!this._touchScaleChangeEnabled) { return; } - this.clickScale(this._normalScaleValueX + this._onSelectedScaleOffset,this._normalScaleValueY + this._onSelectedScaleOffset); + ccs.Widget.prototype.setScale.call(this, this._normalScaleValueX + this._onSelectedScaleOffset,this._normalScaleValueY + this._onSelectedScaleOffset); }, onPressStateChangedToDisabled: function () { diff --git a/extensions/CocoStudio/GUI/UIWidgets/UILoadingBar.js b/extensions/CocoStudio/GUI/UIWidgets/UILoadingBar.js index b428715731..87fbfcdb03 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/UILoadingBar.js +++ b/extensions/CocoStudio/GUI/UIWidgets/UILoadingBar.js @@ -347,6 +347,7 @@ ccs.LoadingBar = ccs.Widget.extend(/** @lends ccs.LoadingBar# */{ this.loadTexture(loadingBar._textureFile, loadingBar._renderBarTexType); this.setCapInsets(loadingBar._capInsets); this.setPercent(loadingBar._percent); + this.setDirection(loadingBar._barType); } }); /** From 22f14d32e959fdf7e4fd724e12b533151928c1b1 Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Fri, 17 Jan 2014 14:44:47 +0800 Subject: [PATCH 11/24] Fixed #3588: correct a mistake of cc.SpriteFrameCache --- cocos2d/actions/CCAction.js | 2 +- cocos2d/core/sprite_nodes/CCSpriteFrameCache.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos2d/actions/CCAction.js b/cocos2d/actions/CCAction.js index f603c14b46..db901bfe18 100644 --- a/cocos2d/actions/CCAction.js +++ b/cocos2d/actions/CCAction.js @@ -66,7 +66,7 @@ cc.Action = cc.Class.extend(/** @lends cc.Action# */{ * @return {object} */ copy:function () { - return cc.clone(this); + return this.clone(); }, /** diff --git a/cocos2d/core/sprite_nodes/CCSpriteFrameCache.js b/cocos2d/core/sprite_nodes/CCSpriteFrameCache.js index 987da0abd1..e8080a5c16 100644 --- a/cocos2d/core/sprite_nodes/CCSpriteFrameCache.js +++ b/cocos2d/core/sprite_nodes/CCSpriteFrameCache.js @@ -188,8 +188,7 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ if (ext == "plist") { var fullPath = fileUtils.fullPathForFilename(filePath); dict = fileUtils.dictionaryWithContentsOfFileThreadSafe(fullPath); - } - else { + } else { dict = JSON.parse(fileUtils.getTextFileData(filePath)); } @@ -206,7 +205,6 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ if (texturePath != "") { // build texture path relative to plist file texturePath = fileUtils.fullPathFromRelativeFile(texturePath, filePath); - } else { // build texture path by replacing file extension texturePath = filePath; @@ -220,9 +218,10 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ } var getTexture = cc.TextureCache.getInstance().addImage(texturePath); - if (getTexture) + if (getTexture){ this._addSpriteFramesWithDictionary(dict, getTexture); - else + this._loadedFileNames.push(filePath); + } else cc.log("cocos2d: cc.SpriteFrameCache: Couldn't load texture"); } break; @@ -241,6 +240,7 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ if (gTexture) { this._addSpriteFramesWithDictionary(dict, gTexture); + this._loadedFileNames.push(filePath); } else { cc.log("cocos2d: cc.SpriteFrameCache: couldn't load texture file. File not found " + textureFileName); } @@ -296,7 +296,7 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ delete(this._spriteFrames[name]); } // XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache - this._loadedFileNames = {}; + this._loadedFileNames.length = 0; }, /** @@ -316,7 +316,7 @@ cc.SpriteFrameCache = cc.Class.extend(/** @lends cc.SpriteFrameCache# */{ //remove it from the cache if (cc.ArrayContainsObject(this._loadedFileNames, plist)) { - cc.ArrayRemoveObject(plist); + cc.ArrayRemoveObject(this._loadedFileNames, plist); } }, From b2cf2e22242e317e0a9b05d5e9faaa55eff3338a Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Fri, 17 Jan 2014 16:25:52 +0800 Subject: [PATCH 12/24] Closed #3733 : add a function "allLayers" to cc.TMXTiledMap --- cocos2d/tileMap_nodes/CCTMXTiledMap.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cocos2d/tileMap_nodes/CCTMXTiledMap.js b/cocos2d/tileMap_nodes/CCTMXTiledMap.js index 108a893645..c3b4140203 100644 --- a/cocos2d/tileMap_nodes/CCTMXTiledMap.js +++ b/cocos2d/tileMap_nodes/CCTMXTiledMap.js @@ -106,8 +106,6 @@ cc.TMXTiledMap = cc.NodeRGBA.extend(/** @lends cc.TMXTiledMap# */{ _objectGroups:null, _mapOrientation:null, //tile properties - //todo delete - _TMXLayers:null, _tileProperties:null, ctor:function(){ @@ -117,7 +115,6 @@ cc.TMXTiledMap = cc.NodeRGBA.extend(/** @lends cc.TMXTiledMap# */{ this._properties = null; this._objectGroups = null; this._mapOrientation = null; - this._TMXLayers = null; this._tileProperties = []; }, @@ -258,26 +255,37 @@ cc.TMXTiledMap = cc.NodeRGBA.extend(/** @lends cc.TMXTiledMap# */{ } } }, - /** return the TMXLayer for the specific layer + + allLayers: function () { + var retArr = [], locChildren = this._children; + for(var i = 0, len = locChildren.length;i< len;i++){ + var layer = locChildren[i]; + if(layer && layer instanceof cc.TMXLayer) + retArr.push(layer); + } + return retArr; + }, + + /** + * return the TMXLayer for the specific layer * @param {String} layerName * @return {cc.TMXLayer} */ getLayer:function (layerName) { if(!layerName || layerName.length === 0) throw "cc.TMXTiledMap.getLayer(): layerName should be non-null or non-empty string."; - - for (var i = 0; i < this._children.length; i++) { - var layer = this._children[i]; + var locChildren = this._children; + for (var i = 0; i < locChildren.length; i++) { + var layer = locChildren[i]; if (layer && layer.getLayerName() == layerName) return layer; } - // layer not found return null; }, /** - * Return the TMXObjectGroup for the secific group + * Return the TMXObjectGroup for the specific group * @param {String} groupName * @return {cc.TMXObjectGroup} */ From d1b2dd04cd034c4f8a484381ea8025ac2e7a7fe7 Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Tue, 21 Jan 2014 14:56:01 +0800 Subject: [PATCH 13/24] Closed 3800: refactoring cc.Point and cc.Size to support two types of parameters. --- cocos2d/core/cocoa/CCGeometry.js | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/cocoa/CCGeometry.js b/cocos2d/core/cocoa/CCGeometry.js index c23ece0922..e2fb1055f7 100644 --- a/cocos2d/core/cocoa/CCGeometry.js +++ b/cocos2d/core/cocoa/CCGeometry.js @@ -31,13 +31,18 @@ //-------------------------------------------------------- /** * @class - * @param {Number} _x + * @param {Number|cc.Point} _x * @param {Number} _y * Constructor */ cc.Point = function (_x, _y) { - this.x = _x || 0; - this.y = _y || 0; + if(arguments.length === 1){ + this.x = _x.x; + this.y = _x.y; + } else { + this.x = _x || 0; + this.y = _y || 0; + } }; cc._PointConst = function (x, y) { @@ -83,6 +88,7 @@ Object.defineProperties(cc._PointConst.prototype, { * @param {Number} x * @param {Number} y * @return {cc.Point} + * @deprecated */ cc.PointMake = function (x, y) { cc.log("cc.PointMake will be deprecated sooner or later. Use cc.p instead."); @@ -91,17 +97,20 @@ cc.PointMake = function (x, y) { /** * Helper macro that creates a cc.Point. - * @param {Number} x + * @param {Number|cc.Point} x * @param {Number} y */ cc.p = function (x, y) { // This can actually make use of "hidden classes" in JITs and thus decrease // memory usage and overall performance drastically - //return new cc.Point(x, y); + // return new cc.Point(x, y); // but this one will instead flood the heap with newly allocated hash maps // giving little room for optimization by the JIT, // note: we have tested this item on Chrome and firefox, it is faster than new cc.Point(x, y) - return {x: x, y: y}; + if(arguments.length === 1) + return {x: x.x, y: x.y}; + else + return {x: x || 0, y: y || 0}; }; // JSB compatbility: in JSB, cc._p reuses objects instead of creating new ones @@ -140,13 +149,18 @@ cc.pointEqualToPoint = function (point1, point2) { /** * @class - * @param {Number} _width + * @param {Number|cc.Size} _width * @param {Number} _height * Constructor */ cc.Size = function (_width, _height) { - this.width = _width || 0; - this.height = _height || 0; + if(arguments.length === 1){ + this.width = _width.width; + this.height = _width.height; + } else { + this.width = _width || 0; + this.height = _height || 0; + } }; cc._SizeConst = function (width, height) { @@ -192,6 +206,7 @@ Object.defineProperties(cc._SizeConst.prototype, { * @param {Number} width * @param {Number} height * @return {cc.Size} + * @deprecated */ cc.SizeMake = function (width, height) { cc.log("cc.SizeMake will be deprecated sooner or later. Use cc.size instead."); @@ -200,18 +215,21 @@ cc.SizeMake = function (width, height) { /** * @function - * @param {Number} w width + * @param {Number|cc.Size} w width or a size object * @param {Number} h height * @return {cc.Size} */ cc.size = function (w, h) { // This can actually make use of "hidden classes" in JITs and thus decrease - // memory usage and overall peformance drastically + // memory usage and overall performance drastically //return new cc.Size(w, h); // but this one will instead flood the heap with newly allocated hash maps // giving little room for optimization by the JIT // note: we have tested this item on Chrome and firefox, it is faster than new cc.Size(w, h) - return { width: w, height: h}; + if(arguments.length === 1) + return { width: w.width, height: w.height}; + else + return { width: w || 0, height: h || 0}; }; // JSB compatbility: in JSB, cc._size reuses objects instead of creating new ones From 8dafac48c190e100ede9ecfa76a1b6f1f66eb306 Mon Sep 17 00:00:00 2001 From: xingsenma Date: Wed, 22 Jan 2014 14:28:46 +0800 Subject: [PATCH 14/24] issue #3767 Add DrawingPrimitive function for cc.DrawNode --- cocos2d/shape_nodes/CCDrawNode.js | 420 ++++++++++++++++++++++++++---- 1 file changed, 367 insertions(+), 53 deletions(-) diff --git a/cocos2d/shape_nodes/CCDrawNode.js b/cocos2d/shape_nodes/CCDrawNode.js index 5f523d7ce5..b1ef806200 100644 --- a/cocos2d/shape_nodes/CCDrawNode.js +++ b/cocos2d/shape_nodes/CCDrawNode.js @@ -88,57 +88,257 @@ cc.__t = function (v) { * @extends cc.Node */ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNodeCanvas# */{ - _buffer:null, - _blendFunc:null, + _buffer: null, + _blendFunc: null, + _lineWidth: 0, + _drawColor: null, + + ctor: function () { + cc.Node.prototype.ctor.call(this); + this._buffer = []; + this._lineWidth = 1; + this._drawColor = new cc.Color4F(255, 255, 255, 255); + this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + }, // ----common function start ---- - getBlendFunc:function () { + getBlendFunc: function () { return this._blendFunc; }, - setBlendFunc:function (blendFunc) { + setBlendFunc: function (blendFunc) { this._blendFunc = blendFunc; }, + + /** + * line width setter + * @param {Number} width + */ + setLineWidth: function (width) { + this._lineWidth = width; + }, + + /** + * line width getter + * @returns {Number} + */ + getLineWidth: function () { + return this._lineWidth; + }, + + /** + * draw color setter + * @param {cc.Color4F} color + */ + setDrawColor: function (color) { + this._drawColor.r = color.r; + this._drawColor.g = color.g; + this._drawColor.b = color.b; + this._drawColor.a = color.a; + }, + + /** + * draw color getter + * @returns {cc.Color4F} + */ + getDrawColor: function () { + return new cc.Color4F(this._drawColor.r, this._drawColor.g, this._drawColor.b, this._drawColor.a); + }, // ----common function end ---- - ctor:function () { - cc.Node.prototype.ctor.call(this); - this._buffer = []; - this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + + /** + * draws a rectangle given the origin and destination point measured in points. + * @param {cc.Point} origin + * @param {cc.Point} destination + * @param {cc.Color4F} fillColor + * @param {Number} lineWidth + * @param {cc.Color4F} lineColor + */ + drawRect: function (origin, destination, fillColor, lineWidth, lineColor) { + lineWidth = lineWidth || this._lineWidth; + lineColor = lineColor || this.getDrawColor(); + var vertices = [ + origin, + cc.p(destination.x, origin.y), + destination, + cc.p(origin.x, destination.y) + ]; + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = vertices; + element.lineWidth = lineWidth; + element.lineColor = lineColor; + element.isClosePolygon = true; + element.isStroke = true; + element.lineCap = "butt"; + element.fillColor = fillColor; + if (fillColor) { + element.isFill = true; + } + this._buffer.push(element); }, - draw:function (ctx) { - var context = ctx || cc.renderContext; - var locEGL_ScaleX = cc.EGLView.getInstance().getScaleX(); + /** + * draws a circle given the center, radius and number of segments. + * @override + * @param {cc.Point} center center of circle + * @param {Number} radius + * @param {Number} angle angle in radians + * @param {Number} segments + * @param {Boolean} drawLineToCenter + * @param {Number} lineWidth + * @param {cc.Color4F} color + */ + drawCircle: function (center, radius, angle, segments, drawLineToCenter, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + + var coef = 2.0 * Math.PI / segments; + var vertices = []; + for (var i = 0; i <= segments; i++) { + var rads = i * coef; + var j = radius * Math.cos(rads + angle) + center.x; + var k = radius * Math.sin(rads + angle) + center.y; + vertices.push(cc.p(j, k)); + } + if (drawLineToCenter) { + vertices.push(cc.p(center.x, center.y)); + } - if ((this._blendFunc && (this._blendFunc.src == gl.SRC_ALPHA) && (this._blendFunc.dst == gl.ONE))) - context.globalCompositeOperation = 'lighter'; + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = vertices; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isClosePolygon = true; + element.isStroke = true; + this._buffer.push(element); + }, - for (var i = 0; i < this._buffer.length; i++) { - var element = this._buffer[i]; - if (element.type === cc.DrawNode.TYPE_DOT) { - context.fillStyle = "rgba(" + (0 | (element.color.r * 255)) + "," + (0 | (element.color.g * 255)) + "," + (0 | (element.color.b * 255)) + "," + element.color.a + ")"; - cc.drawingUtil.drawPoint(element.position, element.radius); - } + /** + * draws a quad bezier path + * @override + * @param {cc.Point} origin + * @param {cc.Point} control + * @param {cc.Point} destination + * @param {Number} segments + * @param {Number} lineWidth + * @param {cc.Color4F} color + */ + drawQuadBezier: function (origin, control, destination, segments, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + + var vertices = []; + var t = 0.0; + for (var i = 0; i < segments; i++) { + var x = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x; + var y = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y; + vertices.push(cc.p(x, y)); + t += 1.0 / segments; + } + vertices.push(cc.p(destination.x, destination.y)); + + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = vertices; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isStroke = true; + element.lineCap = "round"; + this._buffer.push(element); + }, - if (element.type === cc.DrawNode.TYPE_SEGMENT) { - context.strokeStyle = "rgba(" + (0 | (element.color.r * 255)) + "," + (0 | (element.color.g * 255)) + "," + (0 | (element.color.b * 255)) + "," + element.color.a + ")"; - context.lineWidth = element.radius * 2 * locEGL_ScaleX; - context.lineCap = "round"; - cc.drawingUtil.drawLine(element.from, element.to); - } + /** + * draws a cubic bezier path + * @override + * @param {cc.Point} origin + * @param {cc.Point} control1 + * @param {cc.Point} control2 + * @param {cc.Point} destination + * @param {Number} segments + * @param {Number} lineWidth + * @param {cc.Color4F} color + */ + drawCubicBezier: function (origin, control1, control2, destination, segments, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + + var vertices = []; + var t = 0; + for (var i = 0; i < segments; i++) { + var x = Math.pow(1 - t, 3) * origin.x + 3.0 * Math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x; + var y = Math.pow(1 - t, 3) * origin.y + 3.0 * Math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y; + vertices.push(cc.p(x, y)); + t += 1.0 / segments; + } + vertices.push(cc.p(destination.x, destination.y)); + + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = vertices; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isStroke = true; + element.lineCap = "round"; + this._buffer.push(element); + }, + + /** + * draw a CatmullRom curve + * @override + * @param {Array} points + * @param {Number} segments + * @param {Number} lineWidth + * @param {cc.Color4F} color + */ + drawCatmullRom: function (points, segments, lineWidth, color) { + this.drawCardinalSpline(points, 0.5, segments, lineWidth, color); + }, - if (element.type === cc.DrawNode.TYPE_POLY ) { - context.fillStyle = "rgba(" + (0 | (element.fillColor.r * 255)) + "," + (0 | (element.fillColor.g * 255)) + "," - + (0 | (element.fillColor.b * 255)) + "," + element.fillColor.a + ")"; - cc.drawingUtil.drawPoly(element.verts, element.count, false, true); - context.lineWidth = element.borderWidth * 2 * locEGL_ScaleX; - context.lineCap = "round"; - context.strokeStyle = "rgba(" + (0 | (element.borderColor.r * 255)) + "," + (0 | (element.borderColor.g * 255)) + "," - + (0 | (element.borderColor.b * 255)) + "," + element.borderColor.a + ")"; - cc.drawingUtil.drawPoly(element.verts, element.count, true, false); + /** + * draw a cardinal spline path + * @override + * @param {Array} config + * @param {Number} tension + * @param {Number} segments + * @param {Number} lineWidth + * @param {cc.Color4F} color + */ + drawCardinalSpline: function (config, tension, segments, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + + var vertices = []; + var p, lt; + var deltaT = 1.0 / config.length; + + for (var i = 0; i < segments + 1; i++) { + var dt = i / segments; + + // border + if (dt == 1) { + p = config.length - 1; + lt = 1; + } else { + p = 0 | (dt / deltaT); + lt = (dt - deltaT * p) / deltaT; } + + // Interpolate + var newPos = cc.CardinalSplineAt( + cc.getControlPointAt(config, p - 1), + cc.getControlPointAt(config, p - 0), + cc.getControlPointAt(config, p + 1), + cc.getControlPointAt(config, p + 2), + tension, lt); + vertices.push(newPos); } + + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = vertices; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isStroke = true; + element.lineCap = "round"; + this._buffer.push(element); }, /** @@ -147,11 +347,12 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNodeCanvas# */{ * @param {Number} radius * @param {cc.Color4F} color */ - drawDot:function (pos, radius, color) { + drawDot: function (pos, radius, color) { + color = color || this.getDrawColor(); var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_DOT); - element.position = pos; - element.radius = radius; - element.color = color; + element.verts = [pos]; + element.lineWidth = radius; + element.fillColor = color; this._buffer.push(element); }, @@ -159,15 +360,19 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNodeCanvas# */{ * draw a segment with a radius and color * @param {cc.Point} from * @param {cc.Point} to - * @param {Number} radius + * @param {Number} lineWidth * @param {cc.Color4F} color */ - drawSegment:function (from, to, radius, color) { - var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_SEGMENT); - element.from = from; - element.to = to; - element.radius = radius; - element.color = color; + drawSegment: function (from, to, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); + element.verts = [from, to]; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isStroke = true; + element.lineCap = "round"; this._buffer.push(element); }, @@ -175,23 +380,124 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNodeCanvas# */{ * draw a polygon with a fill color and line color * @param {Array} verts * @param {cc.Color4F} fillColor - * @param {Number} borderWidth - * @param {cc.Color4F} borderColor + * @param {Number} lineWidth + * @param {cc.Color4F} color */ - drawPoly:function (verts, fillColor, borderWidth, borderColor) { - var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY ); + drawPoly: function (verts, fillColor, lineWidth, color) { + lineWidth = lineWidth || this._lineWidth; + color = color || this.getDrawColor(); + var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY); element.verts = verts; - element.count = verts.length; element.fillColor = fillColor; - element.borderWidth = borderWidth; - element.borderColor = borderColor; + element.lineWidth = lineWidth; + element.lineColor = color; + element.isClosePolygon = true; + element.isStroke = true; + element.lineCap = "round"; + if (fillColor) { + element.isFill = true; + } this._buffer.push(element); }, + draw: function (ctx) { + var context = ctx || cc.renderContext; + if ((this._blendFunc && (this._blendFunc.src == gl.SRC_ALPHA) && (this._blendFunc.dst == gl.ONE))) + context.globalCompositeOperation = 'lighter'; + + for (var i = 0; i < this._buffer.length; i++) { + var element = this._buffer[i]; + switch (element.type) { + case cc.DrawNode.TYPE_DOT: + this._drawDot(context, element); + break; + case cc.DrawNode.TYPE_SEGMENT: + this._drawSegment(context, element); + break; + case cc.DrawNode.TYPE_POLY: + this._drawPoly(context, element); + break; + } + } + }, + + _drawDot: function (ctx, element) { + var locColor = element.fillColor; + var locPos = element.verts[0]; + var locRadius = element.lineWidth; + var locScaleX = cc.EGLView.getInstance().getScaleX(), locScaleY = cc.EGLView.getInstance().getScaleY(); + + ctx.fillStyle = "rgba(" + (0 | (locColor.r * 255)) + "," + (0 | (locColor.g * 255)) + "," + (0 | (locColor.b * 255)) + "," + locColor.a + ")"; + ctx.beginPath(); + ctx.arc(locPos.x * locScaleX, -locPos.y * locScaleY, locRadius * locScaleX, 0, Math.PI * 2, false); + ctx.closePath(); + ctx.fill(); + }, + + _drawSegment: function (ctx, element) { + var locColor = element.lineColor; + var locFrom = element.verts[0]; + var locTo = element.verts[1]; + var locLineWidth = element.lineWidth; + var locLineCap = element.lineCap; + var locScaleX = cc.EGLView.getInstance().getScaleX(), locScaleY = cc.EGLView.getInstance().getScaleY(); + + ctx.strokeStyle = "rgba(" + (0 | (locColor.r * 255)) + "," + (0 | (locColor.g * 255)) + "," + (0 | (locColor.b * 255)) + "," + locColor.a + ")"; + ctx.lineWidth = locLineWidth * locScaleX; + ctx.beginPath(); + ctx.lineCap = locLineCap; + ctx.moveTo(locFrom.x * locScaleX, -locFrom.y * locScaleY); + ctx.lineTo(locTo.x * locScaleX, -locTo.y * locScaleY); + ctx.stroke(); + }, + + _drawPoly: function (ctx, element) { + var locVertices = element.verts; + var locLineCap = element.lineCap; + var locFillColor = element.fillColor; + var locLineWidth = element.lineWidth; + var locLineColor = element.lineColor; + var locIsClosePolygon = element.isClosePolygon; + var locIsFill = element.isFill; + var locIsStroke = element.isStroke; + if (locVertices == null) + return; + + var firstPoint = locVertices[0]; + var locScaleX = cc.EGLView.getInstance().getScaleX(), locScaleY = cc.EGLView.getInstance().getScaleY(); + + ctx.lineCap = locLineCap; + + if (locFillColor) { + ctx.fillStyle = "rgba(" + (0 | (locFillColor.r * 255)) + "," + (0 | (locFillColor.g * 255)) + "," + + (0 | (locFillColor.b * 255)) + "," + locFillColor.a + ")"; + } + + if (locLineWidth) { + ctx.lineWidth = locLineWidth * locScaleX; + } + if (locLineColor) { + ctx.strokeStyle = "rgba(" + (0 | (locLineColor.r * 255)) + "," + (0 | (locLineColor.g * 255)) + "," + + (0 | (locLineColor.b * 255)) + "," + locLineColor.a + ")"; + } + ctx.beginPath(); + ctx.moveTo(firstPoint.x * locScaleX, -firstPoint.y * locScaleY); + for (var i = 1, len = locVertices.length; i < len; i++) + ctx.lineTo(locVertices[i].x * locScaleX, -locVertices[i].y * locScaleY); + + if (locIsClosePolygon) + ctx.closePath(); + + if (locIsFill) + ctx.fill(); + if (locIsStroke) + ctx.stroke(); + }, + /** * Clear the geometry in the node's buffer. */ - clear:function () { + clear: function () { this._buffer.length = 0; } }); @@ -466,6 +772,14 @@ cc.DrawNode.create = function () { cc._DrawNodeElement = function (type) { this.type = type; + this.verts = verts || null; + this.fillColor = fillColor || null; + this.lineWidth = lineWidth || 0; + this.lineColor = lineColor || null; + this.lineCap = lineCap || "butt"; + this.isClosePolygon = isClosePolygon || false; + this.isFill = isFill || false; + this.isStroke = isStroke || false; }; cc.DrawNode.TYPE_DOT = 0; From 2b78d24fc03cf863d756baaca5817a8b826b2f45 Mon Sep 17 00:00:00 2001 From: xingsenma Date: Wed, 22 Jan 2014 14:38:03 +0800 Subject: [PATCH 15/24] issue #3667: Add DrawingPrimitive function for cc.DrawNode --- cocos2d/shape_nodes/CCDrawNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/shape_nodes/CCDrawNode.js b/cocos2d/shape_nodes/CCDrawNode.js index b1ef806200..74175a2c4d 100644 --- a/cocos2d/shape_nodes/CCDrawNode.js +++ b/cocos2d/shape_nodes/CCDrawNode.js @@ -770,7 +770,7 @@ cc.DrawNode.create = function () { return null; }; -cc._DrawNodeElement = function (type) { +cc._DrawNodeElement = function (type, verts, fillColor, lineWidth, lineColor, lineCap, isClosePolygon, isFill, isStroke) { this.type = type; this.verts = verts || null; this.fillColor = fillColor || null; From b30f39aa676786925891a50eb8a2f51048dae39f Mon Sep 17 00:00:00 2001 From: samael Date: Wed, 22 Jan 2014 14:46:42 +0800 Subject: [PATCH 16/24] Update CCPhysicsSprite.js add function: setIgnoreBodyRotation --- cocos2d/physics_nodes/CCPhysicsSprite.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cocos2d/physics_nodes/CCPhysicsSprite.js b/cocos2d/physics_nodes/CCPhysicsSprite.js index befe804fad..798442d939 100644 --- a/cocos2d/physics_nodes/CCPhysicsSprite.js +++ b/cocos2d/physics_nodes/CCPhysicsSprite.js @@ -92,6 +92,9 @@ cc.log("PhysicsSprite body or PTIMRatio was not set"); } this._super(); + }, + setIgnoreBodyRotation: function(b) { + this._ignoreBodyRotation = b; } }; var chipmunkAPI = { @@ -134,7 +137,7 @@ } }, getRotation:function () { - return this._ignoreBodyRotation ? cc.RADIANS_TO_DEGREES(this._rotationRadiansX) : -cc.RADIANS_TO_DEGREES(this._body.a) + return this._ignoreBodyRotation ? cc.RADIANS_TO_DEGREES(this._rotationRadiansX) : -cc.RADIANS_TO_DEGREES(this._body.a); }, setRotation:function (r) { if (this._ignoreBodyRotation) { @@ -228,7 +231,11 @@ isDirty:function(){ return !this._body.isSleeping(); + }, + setIgnoreBodyRotation: function(b) { + this._ignoreBodyRotation = b; } + }; cc.PhysicsSprite = cc.Sprite.extend(chipmunkAPI); From aeee4561a64ef6da6e4e23b5b08769869b18add1 Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Wed, 22 Jan 2014 17:32:36 +0800 Subject: [PATCH 17/24] Closed 3816: Add a condition to check textureCoord to cc.Sprite --- cocos2d/core/labelTTF/CCLabelTTF.js | 3 ++- cocos2d/core/sprite_nodes/CCSprite.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/labelTTF/CCLabelTTF.js b/cocos2d/core/labelTTF/CCLabelTTF.js index 9342d40177..f6f0f6a167 100644 --- a/cocos2d/core/labelTTF/CCLabelTTF.js +++ b/cocos2d/core/labelTTF/CCLabelTTF.js @@ -907,7 +907,8 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{ locTextureCoordRect.y = rect.y; locTextureCoordRect.width = rect.width; locTextureCoordRect.height = rect.height; - locTextureCoordRect.validRect = !(locTextureCoordRect.width === 0 || locTextureCoordRect.height === 0); + locTextureCoordRect.validRect = !(locTextureCoordRect.width === 0 || locTextureCoordRect.height === 0 + || locTextureCoordRect.x < 0 || locTextureCoordRect.y < 0); var relativeOffset = this._unflippedOffsetPositionFromCenter; if (this._flippedX) diff --git a/cocos2d/core/sprite_nodes/CCSprite.js b/cocos2d/core/sprite_nodes/CCSprite.js index 6caaff0f04..987a012500 100644 --- a/cocos2d/core/sprite_nodes/CCSprite.js +++ b/cocos2d/core/sprite_nodes/CCSprite.js @@ -1402,7 +1402,7 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{ locTextureRect.y = 0 | (rect.y * scaleFactor); locTextureRect.width = 0 | (rect.width * scaleFactor); locTextureRect.height = 0 | (rect.height * scaleFactor); - locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0); + locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0); var relativeOffset = this._unflippedOffsetPositionFromCenter; if (this._flippedX) From 8ba798a9b9abaf606a05dd7da7c2523a1a52899e Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Wed, 22 Jan 2014 18:50:26 +0800 Subject: [PATCH 18/24] Fixed #2245: fixed a bug of Editbox's setPosition --- extensions/CCEditBox/CCdomNode.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/CCEditBox/CCdomNode.js b/extensions/CCEditBox/CCdomNode.js index 7fb2e391ed..754bbade1b 100644 --- a/extensions/CCEditBox/CCdomNode.js +++ b/extensions/CCEditBox/CCdomNode.js @@ -43,7 +43,7 @@ cc.DOM.addMethods = function (x) { cc.DOM.methods = /** @lends cc.DOM# */{ /** * Replace the set position of ccNode - * @param {object|Number} x + * @param {cc.Point|Number} x * @param {Number} y */ setPosition:function (x, y) { @@ -52,7 +52,8 @@ cc.DOM.methods = /** @lends cc.DOM# */{ this._position._y = y; //this._position = cc.p(newPosOrxValue,yValue); } else { - this._position = x; + this._position._x = x.x; + this._position._y = x.y; } this.setNodeDirty(); this.dom.translates(this._position._x, -this._position._y); From c729bb1765a27d17ba5db979d5b7aaa7fc02fd2d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 23 Jan 2014 15:40:17 +0800 Subject: [PATCH 19/24] Fixed #3819: Use WebAudio on iOS --- cocos2d/audio/SimpleAudioEngine.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/audio/SimpleAudioEngine.js b/cocos2d/audio/SimpleAudioEngine.js index 4f031670e2..d8ad233834 100644 --- a/cocos2d/audio/SimpleAudioEngine.js +++ b/cocos2d/audio/SimpleAudioEngine.js @@ -1414,6 +1414,8 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{ * @private */ _endSound: function(sfxCache) { + if (sfxCache.sourceNode.playbackState && sfxCache.sourceNode.playbackState == 3) + return; if (sfxCache.sourceNode.stop) { sfxCache.sourceNode.stop(0); } else { @@ -1837,7 +1839,7 @@ cc.AudioEngine.isMusicPlaying = false; cc.AudioEngine.getInstance = function () { if (!this._instance) { var ua = navigator.userAgent; - if (cc.Browser.supportWebAudio && !(/iPhone OS/.test(ua)||/iPad/.test(ua))) { + if (cc.Browser.supportWebAudio) { this._instance = new cc.WebAudioEngine(); } else { if(cc.Browser.isMobile) // TODO construct a supported list for mobile browser From 092ec2645e6589b15600cb1fe78ce9390afd96f7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 23 Jan 2014 15:46:13 +0800 Subject: [PATCH 20/24] Update samples --- samples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples b/samples index 02a289a5f6..daab7f0c11 160000 --- a/samples +++ b/samples @@ -1 +1 @@ -Subproject commit 02a289a5f6615f36ce0436ffe0cd6188bc433b5d +Subproject commit daab7f0c1146b7d80188c61b7362dc3ca611ef6f From 586fcdde2553e66776858622993045bad4c746c9 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 23 Jan 2014 16:22:44 +0800 Subject: [PATCH 21/24] Fixed #3824: EGLView now works well without initialization of director --- HelloHTML5World/main.js | 5 +++-- cocos2d/core/platform/CCEGLView.js | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/HelloHTML5World/main.js b/HelloHTML5World/main.js index bd9593d198..a6af2f643d 100644 --- a/HelloHTML5World/main.js +++ b/HelloHTML5World/main.js @@ -40,12 +40,13 @@ var cocos2dApp = cc.Application.extend({ alert("Browser doesn't support WebGL"); return false; } - // initialize director - var director = cc.Director.getInstance(); cc.EGLView.getInstance().resizeWithBrowserSize(true); cc.EGLView.getInstance().setDesignResolutionSize(800, 450, cc.RESOLUTION_POLICY.SHOW_ALL); + // initialize director + var director = cc.Director.getInstance(); + // turn on display FPS director.setDisplayStats(this.config['showFPS']); diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 6dfba308e7..70199ff039 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -828,7 +828,10 @@ cc.EGLView = cc.Class.extend(/** @lends cc.EGLView# */{ cc.EGLView.getInstance = function () { if (!this._instance) { - this._instance = new cc.EGLView(); + // First init director + cc.Director.getInstance(); + + this._instance = this._instance || new cc.EGLView(); this._instance.initialize(); } return this._instance; From 52a4b24c98693a43bb23c8194ad46c866bb9844b Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Fri, 24 Jan 2014 15:47:34 +0800 Subject: [PATCH 22/24] Fixed #3825: Fixed a bug of SimpleAudioEngine that its state is incorrect and add some WebAudio's keyword to cocos2d_externs.js --- cocos2d/audio/SimpleAudioEngine.js | 125 ++++++++++++++++++++++++- cocos2d/core/cocos2d_externs.js | 3 + cocos2d/core/platform/CCApplication.js | 14 +-- 3 files changed, 129 insertions(+), 13 deletions(-) diff --git a/cocos2d/audio/SimpleAudioEngine.js b/cocos2d/audio/SimpleAudioEngine.js index d8ad233834..b926657b61 100644 --- a/cocos2d/audio/SimpleAudioEngine.js +++ b/cocos2d/audio/SimpleAudioEngine.js @@ -39,10 +39,12 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{ _effectsVolume:1, // the volume applied to all effects _playingMusic:null, // the music being played, when null, no music is being played; when not null, it may be playing or paused _resPath : "", //root path for resources + _pausedPlayings: null, ctor:function(){ this._audioIDList = {}; this._supportedFormat = []; + this._pausedPlayings = []; }, /** @@ -642,6 +644,55 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */ locEffectList[elt] = []; return locEffectList[elt]; } + }, + + _pausePlaying: function(){ + var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList; + var tmpArr, au; + if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) { + au = locSoundList[this._playingMusic].audio; + if (!au.paused) { + au.pause(); + cc.AudioEngine.isMusicPlaying = false; + locPausedPlayings.push(au); + } + } + + var locEffectList = this._effectList; + for (var selKey in locEffectList) { + tmpArr = locEffectList[selKey]; + for (var j = 0; j < tmpArr.length; j++) { + au = tmpArr[j]; + if (!au.ended && !au.paused) { + au.pause(); + locPausedPlayings.push(au); + } + } + } + }, + + _resumePlaying: function(){ + var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList; + var tmpArr, au; + if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) { + au = locSoundList[this._playingMusic].audio; + if (locPausedPlayings.indexOf(au) !== -1) { + au.play(); + au.addEventListener("pause", this._musicListenerBound, false); + cc.AudioEngine.isMusicPlaying = true; + } + } + + var locEffectList = this._effectList; + for (var selKey in locEffectList) { + tmpArr = locEffectList[selKey]; + for (var j = 0; j < tmpArr.length; j++) { + au = tmpArr[j]; + if (!au.ended && locPausedPlayings.indexOf(au) !== -1) + au.play(); + } + } + locPausedPlayings.length = 0; } }); @@ -1102,6 +1153,32 @@ cc.SimpleAudioEngineForMobile = cc.SimpleAudioEngine.extend({ this._isPauseForList = false; this.resumeMusic(); } + }, + + _pausePlaying: function(){ + var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList, au; + if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) { + au = locSoundList[this._playingMusic].audio; + if (!au.paused) { + au.pause(); + cc.AudioEngine.isMusicPlaying = false; + locPausedPlayings.push(au); + } + } + this.stopAllEffects(); + }, + + _resumePlaying: function(){ + var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList, au; + if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) { + au = locSoundList[this._playingMusic].audio; + if (locPausedPlayings.indexOf(au) !== -1) { + au.play(); + au.addEventListener("pause", this._musicListenerBound, false); + cc.AudioEngine.isMusicPlaying = true; + } + } + locPausedPlayings.length = 0; } }); @@ -1825,6 +1902,48 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{ if (keyName in this._audioData) delete this._audioData[keyName]; + }, + + _pausePlaying: function(){ + var locPausedPlayings = this._pausedPlayings; + if (this.isMusicPlaying()){ + locPausedPlayings.push(this._playingMusic); + this._pauseSound(this._playingMusic); + } + + var locEffects = this._effects; + for (var selKey in locEffects) { + var selEffectList = locEffects[selKey]; + for (var idx = 0, len = selEffectList.length; idx < len; idx++) { + var sfxCache = selEffectList[idx]; + if (sfxCache && this._isSoundPlaying(sfxCache)) { + locPausedPlayings.push(sfxCache); + this._pauseSound(sfxCache); + } + } + } + }, + + _resumePlaying: function(){ + var locPausedPlayings = this._pausedPlayings, locVolume = this.getMusicVolume(); + + var locMusic = this._playingMusic; + // can resume only when it's paused + if (locMusic && this._isSoundPaused(locMusic) && locPausedPlayings.indexOf(locMusic) != -1) + this._playingMusic = this._resumeSound(locMusic, locVolume); + + var locEffects = this._effects; + for (var selKey in locEffects){ + var selEffects = locEffects[selKey]; + for (var idx = 0, len = selEffects.length; idx < len; idx++) { + var sfxCache = selEffects[idx]; + if (this._isSoundPaused(sfxCache) &&locPausedPlayings.indexOf(sfxCache) != -1) { + selEffects[idx] = this._resumeSound(sfxCache, locVolume); + this._updateEffectsList(sfxCache, selEffects[idx]); + } + } + } + locPausedPlayings.length = 0; } }); @@ -1838,15 +1957,15 @@ cc.AudioEngine.isMusicPlaying = false; */ cc.AudioEngine.getInstance = function () { if (!this._instance) { - var ua = navigator.userAgent; - if (cc.Browser.supportWebAudio) { +/* if (cc.Browser.supportWebAudio) { this._instance = new cc.WebAudioEngine(); } else { if(cc.Browser.isMobile) // TODO construct a supported list for mobile browser this._instance = new cc.SimpleAudioEngineForMobile(); else this._instance = new cc.SimpleAudioEngine(); - } + }*/ + this._instance = new cc.SimpleAudioEngineForMobile(); this._instance.init(); } return this._instance; diff --git a/cocos2d/core/cocos2d_externs.js b/cocos2d/core/cocos2d_externs.js index 3040e25c26..97c83972eb 100644 --- a/cocos2d/core/cocos2d_externs.js +++ b/cocos2d/core/cocos2d_externs.js @@ -59,5 +59,8 @@ CSSProperties.prototype.destination; CSSProperties.prototype.decodeAudioData; CSSProperties.prototype.gain; CSSProperties.prototype.connect; +CSSProperties.prototype.playbackState; +CSSProperties.prototype.noteGrainOn; +CSSProperties.prototype.noteOn; diff --git a/cocos2d/core/platform/CCApplication.js b/cocos2d/core/platform/CCApplication.js index 00d97f87c1..ccc0c52a1c 100644 --- a/cocos2d/core/platform/CCApplication.js +++ b/cocos2d/core/platform/CCApplication.js @@ -260,11 +260,9 @@ cc.setup = function (el, width, height) { var audioEngine = cc.AudioEngine.getInstance(); if (!document[hidden]){ cc.Director.getInstance()._resetLastUpdate(); - audioEngine.resumeAllEffects(); - audioEngine.resumeMusic(); + audioEngine._resumePlaying(); } else{ - audioEngine.pauseAllEffects(); - audioEngine.pauseMusic(); + audioEngine._pausePlaying(); } } @@ -273,15 +271,11 @@ cc.setup = function (el, width, height) { cc.isAddedHiddenEvent = false; window.addEventListener("focus", function () { if(!cc.AudioEngine) return; - var audioEngine = cc.AudioEngine.getInstance(); - audioEngine.resumeAllEffects(); - audioEngine.resumeMusic(); + cc.AudioEngine.getInstance()._resumePlaying(); }, false); window.addEventListener("blur", function () { if(!cc.AudioEngine) return; - var audioEngine = cc.AudioEngine.getInstance(); - audioEngine.pauseAllEffects(); - audioEngine.pauseMusic(); + cc.AudioEngine.getInstance()._pausePlaying(); }, false); } else { cc.isAddedHiddenEvent = true; From 83a2b0980d16c69ae0349549804db8c24c7697c1 Mon Sep 17 00:00:00 2001 From: dingpinglv Date: Fri, 24 Jan 2014 15:48:22 +0800 Subject: [PATCH 23/24] Closed #3825: remove the test codes. --- cocos2d/audio/SimpleAudioEngine.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cocos2d/audio/SimpleAudioEngine.js b/cocos2d/audio/SimpleAudioEngine.js index b926657b61..541f653bf5 100644 --- a/cocos2d/audio/SimpleAudioEngine.js +++ b/cocos2d/audio/SimpleAudioEngine.js @@ -1957,15 +1957,14 @@ cc.AudioEngine.isMusicPlaying = false; */ cc.AudioEngine.getInstance = function () { if (!this._instance) { -/* if (cc.Browser.supportWebAudio) { + if (cc.Browser.supportWebAudio) { this._instance = new cc.WebAudioEngine(); } else { - if(cc.Browser.isMobile) // TODO construct a supported list for mobile browser + if (cc.Browser.isMobile) // TODO construct a supported list for mobile browser this._instance = new cc.SimpleAudioEngineForMobile(); else this._instance = new cc.SimpleAudioEngine(); - }*/ - this._instance = new cc.SimpleAudioEngineForMobile(); + } this._instance.init(); } return this._instance; From 3674dadb6dfdcd2889c0d32fff239cffd4739283 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 24 Jan 2014 22:57:03 +0800 Subject: [PATCH 24/24] Fixed #3838: Allow retina display only on apple device to resolve the bug --- cocos2d/core/platform/CCEGLView.js | 8 +++++--- cocos2d/core/platform/Sys.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 70199ff039..eb27b949c6 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -848,13 +848,15 @@ cc.EGLView.getInstance = function () { cc.ContainerStrategy = cc.Class.extend({ // Adjust canvas's size for retina display - _adjustRetina: true, + _adjustRetina: false, /** * Manipulation before appling the strategy * @param {cc.EGLView} The target view */ preApply: function (view) { + if(sys.os == "iOS" || sys.os == "OS X") + this._adjustRetina = true; }, /** @@ -1017,24 +1019,24 @@ cc.ContentStrategy = cc.Class.extend({ var EqualToWindow = EqualToFrame.extend({ preApply: function (view) { + this._super(view); view._frame = document.documentElement; }, apply: function (view) { this._super(view); - this._fixContainer(); } }); var ProportionalToWindow = ProportionalToFrame.extend({ preApply: function (view) { + this._super(view); view._frame = document.documentElement; }, apply: function (view, designedResolution) { this._super(view, designedResolution); - this._fixContainer(); } }); diff --git a/cocos2d/core/platform/Sys.js b/cocos2d/core/platform/Sys.js index 1eebcb8cac..d9ae941c66 100644 --- a/cocos2d/core/platform/Sys.js +++ b/cocos2d/core/platform/Sys.js @@ -77,14 +77,14 @@ Object.defineProperties(sys, var OSName=navigator.appVersion; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; + else if( iOS ) + OSName = "iOS"; else if (navigator.appVersion.indexOf("Mac")!=-1) OSName="OS X"; else if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; else if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; - else if( iOS ) - OSName = "iOS"; else if( isAndroid ) OSName = "Android"; return OSName;