From 36b5f75aecf3d16c2d51f8f0b37f67a403705c78 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 22 Feb 2016 17:42:59 +0800 Subject: [PATCH 1/2] remove contentScaleFactor --- cocos2d/core/CCDrawingPrimitivesWebGL.js | 2 +- cocos2d/core/label/CCSGLabel.js | 13 +-- cocos2d/core/labelttf/CCLabelTTF.js | 23 ++-- cocos2d/core/platform/CCEGLView.js | 8 -- cocos2d/core/platform/CCMacro.js | 98 ---------------- cocos2d/core/scenes/CCLoaderScene.js | 1 - cocos2d/core/sprites/CCSGSprite.js | 11 +- .../core/sprites/CCSGSpriteCanvasRenderCmd.js | 15 +-- .../core/sprites/CCSGSpriteWebGLRenderCmd.js | 6 +- cocos2d/core/sprites/CCScale9Sprite.js | 10 +- cocos2d/core/sprites/CCSpriteFrame.js | 12 +- cocos2d/core/textures/CCTexture2D.js | 7 +- cocos2d/labels/CCLabelAtlas.js | 5 +- cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js | 2 +- cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js | 4 - cocos2d/labels/CCLabelBMFont.js | 7 +- .../CCSGParticleSystemWebGLRenderCmd.js | 9 +- .../CCRenderTextureCanvasRenderCmd.js | 9 +- .../CCRenderTextureWebGLRenderCmd.js | 12 +- cocos2d/tilemap/CCTMXLayer.js | 12 +- cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js | 9 +- jsb/jsb-tex-sprite-frame.js | 3 - jsb/versions/jsb-polyfill-v3.5.js | 3 - .../visual-tests/src/SpriteTest/SpriteTest.js | 107 ------------------ 24 files changed, 68 insertions(+), 320 deletions(-) diff --git a/cocos2d/core/CCDrawingPrimitivesWebGL.js b/cocos2d/core/CCDrawingPrimitivesWebGL.js index 660015354e..4c3a75c0ee 100644 --- a/cocos2d/core/CCDrawingPrimitivesWebGL.js +++ b/cocos2d/core/CCDrawingPrimitivesWebGL.js @@ -450,7 +450,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# * @param {Number} pointSize */ setPointSize:function (pointSize) { - this._pointSize = pointSize * cc.contentScaleFactor(); + this._pointSize = pointSize; }, /** diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 3d54440457..88dde604f0 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -685,8 +685,7 @@ cc.BMFontHelper = { var longestLine = 0; var letterRight = 0; - var contentScaleFactor = cc.contentScaleFactor(); - var lineSpacing = this._lineSpacing * contentScaleFactor; + var lineSpacing = this._lineSpacing; var highestY = 0; var lowestY = 0; var letterDef = null; @@ -728,7 +727,7 @@ cc.BMFontHelper = { continue; } - var letterX = (nextLetterX + letterDef._offsetX * this._bmfontScale) / contentScaleFactor; + var letterX = nextLetterX + letterDef._offsetX * this._bmfontScale; if (this._isWrapText && this._maxLineWidth > 0 @@ -746,7 +745,7 @@ cc.BMFontHelper = { letterPosition.x = letterX; } - letterPosition.y = (nextTokenY - letterDef._offsetY * this._bmfontScale) / contentScaleFactor; + letterPosition.y = nextTokenY - letterDef._offsetY * this._bmfontScale; this._recordLetterInfo(letterPosition, character, letterIndex, lineIndex); if (letterIndex + 1 < this._horizontalKernings.length && letterIndex < textLen - 1) { @@ -788,7 +787,7 @@ cc.BMFontHelper = { this._linesWidth.push(letterRight); this._numberOfLines = lineIndex + 1; - this._textDesiredHeight = (this._numberOfLines * this._lineHeight * this._bmfontScale) / contentScaleFactor; + this._textDesiredHeight = this._numberOfLines * this._lineHeight * this._bmfontScale; if (this._numberOfLines > 1) { this._textDesiredHeight += (this._numberOfLines - 1) * this._lineSpacing; } @@ -1001,7 +1000,7 @@ cc.BMFontHelper = { _updateBMFontScale: function() { if (this._labelType === _ccsg.Label.Type.BMFont) { var originalFontSize = this._fontAtlas._fontSize; - this._bmfontScale = this._fontSize * cc.contentScaleFactor() / originalFontSize; + this._bmfontScale = this._fontSize / originalFontSize; } else { this._bmfontScale = 1; } @@ -1047,8 +1046,6 @@ cc.BMFontHelper = { var letterDefinition = new cc.FontLetterDefinition(); var tempRect = locFontDict[fontDef].rect; - cc.rectPointsToPixels(tempRect); - letterDefinition._offsetX = locFontDict[fontDef].xOffset; letterDefinition._offsetY = locFontDict[fontDef].yOffset; diff --git a/cocos2d/core/labelttf/CCLabelTTF.js b/cocos2d/core/labelttf/CCLabelTTF.js index c7b406d5f3..28a9759a9e 100644 --- a/cocos2d/core/labelttf/CCLabelTTF.js +++ b/cocos2d/core/labelttf/CCLabelTTF.js @@ -272,7 +272,7 @@ cc.LabelTTF = _ccsg.Sprite.extend(/** @lends cc.LabelTTF# */{ * @return {cc.FontDefinition} */ getTextDefinition: function () { - return this._prepareTextDefinition(false); + return this._prepareTextDefinition(); }, /** @@ -535,18 +535,12 @@ cc.LabelTTF = _ccsg.Sprite.extend(/** @lends cc.LabelTTF# */{ this._renderCmd.setDirtyFlag(flags.colorDirty|flags.opacityDirty|flags.textDirty); }, - _prepareTextDefinition: function (adjustForResolution) { + _prepareTextDefinition: function () { var texDef = new cc.FontDefinition(); - if (adjustForResolution) { - texDef.fontSize = this._fontSize; - texDef.boundingWidth = cc.contentScaleFactor() * this._dimensions.width; - texDef.boundingHeight = cc.contentScaleFactor() * this._dimensions.height; - } else { - texDef.fontSize = this._fontSize; - texDef.boundingWidth = this._dimensions.width; - texDef.boundingHeight = this._dimensions.height; - } + texDef.fontSize = this._fontSize; + texDef.boundingWidth = this._dimensions.width; + texDef.boundingHeight = this._dimensions.height; texDef.fontName = this._fontName; texDef.textAlign = this._hAlignment; @@ -567,8 +561,8 @@ cc.LabelTTF = _ccsg.Sprite.extend(/** @lends cc.LabelTTF# */{ texDef.shadowBlur = this._shadowBlur; texDef.shadowOpacity = this._shadowOpacity; - texDef.shadowOffsetX = (adjustForResolution ? cc.contentScaleFactor() : 1) * this._shadowOffset.x; - texDef.shadowOffsetY = (adjustForResolution ? cc.contentScaleFactor() : 1) * this._shadowOffset.y; + texDef.shadowOffsetX = this._shadowOffset.x; + texDef.shadowOffsetY = this._shadowOffset.y; } else texDef._shadowEnabled = false; @@ -735,8 +729,7 @@ cc.LabelTTF = _ccsg.Sprite.extend(/** @lends cc.LabelTTF# */{ }, setTextureRect: function (rect, rotated, untrimmedSize) { - //set needConvert to false - _ccsg.Sprite.prototype.setTextureRect.call(this, rect, rotated, untrimmedSize, false); + _ccsg.Sprite.prototype.setTextureRect.call(this, rect, rotated, untrimmedSize); }, /** diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 3dff28e9b0..69d01acd5d 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -344,14 +344,6 @@ cc.EGLView = cc._Class.extend(/** @lends cc.view# */{ } }, - // RenderTexture hacker - _setScaleXYForRenderTexture: function () { - //hack for RenderTexture on canvas mode when adapting multiple resolution resources - var scaleFactor = cc.contentScaleFactor(); - this._scaleX = scaleFactor; - this._scaleY = scaleFactor; - }, - // Other helper functions _resetScale: function () { this._scaleX = this._originalScaleX; diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index 27ccbab51e..830039c188 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -234,104 +234,6 @@ cc.incrementGLDraws = function (addNumber) { */ cc.FLT_EPSILON = 0.0000001192092896; -/** - *

- * On Mac it returns 1;
- * On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1 - *

- * @return {Number} - * @method contentScaleFactor - */ -cc.contentScaleFactor = cc.IS_RETINA_DISPLAY_SUPPORTED ? function () { - return cc.director.getContentScaleFactor(); -} : function () { - return 1; -}; - -/** - * Converts a Point in points to pixels - * @param {Vec2} points - * @return {Vec2} - * @method pointPointsToPixels - */ -cc.pointPointsToPixels = function (points) { - var scale = cc.contentScaleFactor(); - return cc.p(points.x * scale, points.y * scale); -}; - -/** - * Converts a Point in pixels to points - * @param {Rect} pixels - * @return {Vec2} - * @method pointPixelsToPoints - */ -cc.pointPixelsToPoints = function (pixels) { - var scale = cc.contentScaleFactor(); - return cc.p(pixels.x / scale, pixels.y / scale); -}; - -cc._pointPixelsToPointsOut = function(pixels, outPoint){ - var scale = cc.contentScaleFactor(); - outPoint.x = pixels.x / scale; - outPoint.y = pixels.y / scale; -}; - -/** - * Converts a Size in points to pixels - * @param {Size} sizeInPoints - * @return {Size} - * @method sizePointsToPixels - */ -cc.sizePointsToPixels = function (sizeInPoints) { - var scale = cc.contentScaleFactor(); - return cc.size(sizeInPoints.width * scale, sizeInPoints.height * scale); -}; - -/** - * Converts a size in pixels to points - * @param {Size} sizeInPixels - * @return {Size} - * @method sizePixelsToPoints - */ -cc.sizePixelsToPoints = function (sizeInPixels) { - var scale = cc.contentScaleFactor(); - return cc.size(sizeInPixels.width / scale, sizeInPixels.height / scale); -}; - -cc._sizePixelsToPointsOut = function (sizeInPixels, outSize) { - var scale = cc.contentScaleFactor(); - outSize.width = sizeInPixels.width / scale; - outSize.height = sizeInPixels.height / scale; -}; - -/** - * Converts a rect in pixels to points - * @param {Rect} pixel - * @return {Rect} - * @method rectPixelsToPoints - */ -cc.rectPixelsToPoints = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (pixel) { - var scale = cc.contentScaleFactor(); - return cc.rect(pixel.x / scale, pixel.y / scale, - pixel.width / scale, pixel.height / scale); -} : function (p) { - return cc.rect(p); -}; - -/** - * Converts a rect in points to pixels - * @param {Rect} point - * @return {Rect} - * @method rectPointsToPixels - */ -cc.rectPointsToPixels = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (point) { - var scale = cc.contentScaleFactor(); - return cc.rect(point.x * scale, point.y * scale, - point.width * scale, point.height * scale); -} : function (p) { - return cc.rect(p); -}; - //some gl constant variable /** * @property {Number} ONE diff --git a/cocos2d/core/scenes/CCLoaderScene.js b/cocos2d/core/scenes/CCLoaderScene.js index 41b205ba27..bd26a1514e 100644 --- a/cocos2d/core/scenes/CCLoaderScene.js +++ b/cocos2d/core/scenes/CCLoaderScene.js @@ -78,7 +78,6 @@ cc.LoaderScene = _ccsg.Scene.extend({ texture2d.initWithElement(img); texture2d.handleLoadedTexture(); var logo = self._logo = new _ccsg.Sprite(texture2d); - logo.setScale(cc.contentScaleFactor()); logo.x = centerPos.x; logo.y = centerPos.y; self._bgLayer.addChild(logo, 10); diff --git a/cocos2d/core/sprites/CCSGSprite.js b/cocos2d/core/sprites/CCSGSprite.js index 8ec4d9aa21..e8d8ead0fd 100644 --- a/cocos2d/core/sprites/CCSGSprite.js +++ b/cocos2d/core/sprites/CCSGSprite.js @@ -758,15 +758,14 @@ _ccsg.Sprite = _ccsg.Node.extend({ * @param {cc.Rect} rect a rect of texture * @param {Boolean} [rotated] Whether or not the texture is rotated * @param {cc.Size} [untrimmedSize] The original pixels size of the texture - * @param {Boolean} [needConvert] contentScaleFactor switch */ - setTextureRect: function (rect, rotated, untrimmedSize, needConvert) { + setTextureRect: function (rect, rotated, untrimmedSize) { var _t = this; _t._rectRotated = rotated || false; _t.setContentSize(untrimmedSize || rect); _t.setVertexRect(rect); - _t._renderCmd._setTextureCoords(rect, needConvert); + _t._renderCmd._setTextureCoords(rect); var relativeOffsetX = _t._unflippedOffsetPositionFromCenter.x, relativeOffsetY = _t._unflippedOffsetPositionFromCenter.y; if (_t._flippedX) @@ -897,10 +896,10 @@ _ccsg.Sprite = _ccsg.Node.extend({ */ getSpriteFrame: function () { return new cc.SpriteFrame(this._texture, - cc.rectPointsToPixels(this._rect), + this._rect, this._rectRotated, - cc.pointPointsToPixels(this._unflippedOffsetPositionFromCenter), - cc.sizePointsToPixels(this._contentSize)); + this._unflippedOffsetPositionFromCenter, + this._contentSize); }, /** diff --git a/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js index df177ee33a..5e137ed893 100644 --- a/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js @@ -277,15 +277,12 @@ node.emit("load"); }; - proto._setTextureCoords = function (rect, needConvert) { - if (needConvert === undefined) - needConvert = true; - var locTextureRect = this._textureCoord, - scaleFactor = needConvert ? cc.contentScaleFactor() : 1; - locTextureRect.renderX = locTextureRect.x = 0 | (rect.x * scaleFactor); - locTextureRect.renderY = locTextureRect.y = 0 | (rect.y * scaleFactor); - locTextureRect.width = 0 | (rect.width * scaleFactor); - locTextureRect.height = 0 | (rect.height * scaleFactor); + proto._setTextureCoords = function (rect) { + var locTextureRect = this._textureCoord; + locTextureRect.renderX = locTextureRect.x = 0 | rect.x; + locTextureRect.renderY = locTextureRect.y = 0 | rect.y; + locTextureRect.width = 0 | rect.width; + locTextureRect.height = 0 | rect.height; locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0); }; diff --git a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js index 05f2331ff6..60ebb6a47f 100644 --- a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js @@ -143,11 +143,7 @@ node.emit("load"); }; - proto._setTextureCoords = function (rect, needConvert) { - if (needConvert === undefined) - needConvert = true; - if (needConvert) - rect = cc.rectPointsToPixels(rect); + proto._setTextureCoords = function (rect) { var node = this._node; var tex = node._batchNode ? node.textureAtlas.texture : node._texture; diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index abdeb63633..51e1a04345 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -125,7 +125,7 @@ var simpleQuadGenerator = { var atlasWidth = spriteFrame._texture.getPixelWidth(); var atlasHeight = spriteFrame._texture.getPixelHeight(); - var textureRect = cc.rectPointsToPixels(spriteFrame.getRect()); + var textureRect = spriteFrame.getRect(); //uv computation should take spritesheet into account. var u0, u3; @@ -255,7 +255,7 @@ var scale9QuadGenerator = { bottomHeight = insetBottom; centerHeight = rect.height - topHeight - bottomHeight; - var textureRect = cc.rectPointsToPixels(spriteFrame.getRect()); + var textureRect = spriteFrame.getRect(); //uv computation should take spritesheet into account. var u0, u1, u2, u3; @@ -346,7 +346,7 @@ var tiledQuadGenerator = { var atlasWidth = spriteFrame._texture.getPixelWidth(); var atlasHeight = spriteFrame._texture.getPixelHeight(); - var textureRect = cc.rectPointsToPixels(spriteFrame.getRect()); + var textureRect = spriteFrame.getRect(); //uv computation should take spritesheet into account. var u0, u3; @@ -494,7 +494,7 @@ var fillQuadGeneratorBar = { var atlasWidth = spriteFrame._texture.getPixelWidth(); var atlasHeight = spriteFrame._texture.getPixelHeight(); - var textureRect = cc.rectPointsToPixels(spriteFrame.getRect()); + var textureRect = spriteFrame.getRect(); //uv computation should take spritesheet into account. var u0, u3; @@ -843,7 +843,7 @@ var fillQuadGeneratorRadial = { var atlasWidth = spriteFrame._texture.getPixelWidth(); var atlasHeight = spriteFrame._texture.getPixelHeight(); - var textureRect = cc.rectPointsToPixels(spriteFrame.getRect()); + var textureRect = spriteFrame.getRect(); //uv computation should take spritesheet into account. var u0, u3; diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index c5f341cf10..d7891beb19 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -195,7 +195,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ rect.height = rectInPixels.height; } - this._rect = cc.rectPixelsToPoints(rectInPixels); + this._rect = rectInPixels; }, /** @@ -240,7 +240,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ locRect.width = rect.width; locRect.height = rect.height; } - this._rectInPixels = cc.rectPointsToPixels(rect); + this._rectInPixels = rect; }, /** @@ -265,7 +265,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this._offsetInPixels.y = offsetInPixels.y; } - this._offset = cc.pointPixelsToPoints(offsetInPixels); + this._offset = offsetInPixels; }, /** @@ -290,7 +290,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this._originalSizeInPixels.height = sizeInPixels.height; } - this._originalSize = cc.sizePixelsToPoints(sizeInPixels); + this._originalSize = sizeInPixels; }, /** @@ -315,7 +315,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this._originalSize.height = size.height; } - this._originalSizeInPixels = cc.sizePointsToPixels(size); + this._originalSizeInPixels = size; }, /** @@ -394,7 +394,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this._offset.x = offsets.x; this._offset.y = offsets.y; } - this._offsetInPixels = cc.pointPointsToPixels(offsets); + this._offsetInPixels = offsets; }, /** diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index b1f81cc717..db6e325ac7 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -194,15 +194,14 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{ * @returns {Size} */ getContentSize: function () { - var locScaleFactor = cc.contentScaleFactor(); - return cc.size(this._contentSize.width / locScaleFactor, this._contentSize.height / locScaleFactor); + return cc.size(this._contentSize.width, this._contentSize.height); }, _getWidth: function () { - return this._contentSize.width / cc.contentScaleFactor(); + return this._contentSize.width; }, _getHeight: function () { - return this._contentSize.height / cc.contentScaleFactor(); + return this._contentSize.height; }, /** diff --git a/cocos2d/labels/CCLabelAtlas.js b/cocos2d/labels/CCLabelAtlas.js index 84386be0b3..ee1deea62a 100644 --- a/cocos2d/labels/CCLabelAtlas.js +++ b/cocos2d/labels/CCLabelAtlas.js @@ -124,9 +124,8 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{ } textureFilename = cc.path.changeBasename(charMapFile, dict["textureFilename"]); - var locScaleFactor = cc.contentScaleFactor(); - width = parseInt(dict["itemWidth"], 10) / locScaleFactor; - height = parseInt(dict["itemHeight"], 10) / locScaleFactor; + width = parseInt(dict["itemWidth"], 10); + height = parseInt(dict["itemHeight"], 10); startChar = String.fromCharCode(parseInt(dict["firstChar"], 10)); } else { textureFilename = charMapFile; diff --git a/cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js b/cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js index 3d3df03694..680108c5ae 100644 --- a/cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js +++ b/cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js @@ -42,7 +42,7 @@ var locString = node._string || ""; var n = locString.length; var texture = this._textureToRender; - var locItemWidth = node._itemWidth , locItemHeight = node._itemHeight; //needn't multiply cc.contentScaleFactor(), because sprite's draw will do this + var locItemWidth = node._itemWidth , locItemHeight = node._itemHeight; for (var i = 0, cr = -1; i < n; i++) { var a = locString.charCodeAt(i) - node._mapStartChar.charCodeAt(0); diff --git a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js index 87e9fa79f5..d9d07d6347 100644 --- a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js +++ b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js @@ -64,10 +64,6 @@ var textureHigh = texture.getPixelHeight(); var itemWidthInPixels = node._itemWidth; var itemHeightInPixels = node._itemHeight; - if (!node._ignoreContentScaleFactor) { - itemWidthInPixels = node._itemWidth * cc.contentScaleFactor(); - itemHeightInPixels = node._itemHeight * cc.contentScaleFactor(); - } if (n > locTextureAtlas.getCapacity()) cc.log("cc.LabelAtlas._updateAtlasValues(): Invalid String length"); var quads = locTextureAtlas.quads; diff --git a/cocos2d/labels/CCLabelBMFont.js b/cocos2d/labels/CCLabelBMFont.js index d21ec4f8bd..a83faf33aa 100644 --- a/cocos2d/labels/CCLabelBMFont.js +++ b/cocos2d/labels/CCLabelBMFont.js @@ -345,7 +345,6 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ } var rect = cc.rect(fontDef.rect.x, fontDef.rect.y, fontDef.rect.width, fontDef.rect.height); - rect = cc.rectPixelsToPoints(rect); rect.x += self._imageOffset.x; rect.y += self._imageOffset.y; @@ -366,8 +365,8 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ var yOffset = locCfg.commonHeight - fontDef.yOffset; var fontPos = cc.p(nextFontPositionX + fontDef.xOffset + fontDef.rect.width * 0.5 + kerningAmount, - nextFontPositionY + yOffset - rect.height * 0.5 * cc.contentScaleFactor()); - fontChar.setPosition(cc.pointPixelsToPoints(fontPos)); + nextFontPositionY + yOffset - rect.height * 0.5); + fontChar.setPosition(fontPos); // update kerning nextFontPositionX += fontDef.xAdvance + kerningAmount; @@ -384,7 +383,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ else tmpSize.width = longestLine; tmpSize.height = totalHeight; - self.setContentSize(cc.sizePixelsToPoints(tmpSize)); + self.setContentSize(tmpSize); }, /** diff --git a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js index 9c36609b80..8aab337140 100644 --- a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js +++ b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js @@ -209,13 +209,12 @@ proto.initTexCoordsWithRect = function(pointRect){ var node = this._node; var texture = node.texture; - var scaleFactor = cc.contentScaleFactor(); // convert to pixels coords var rect = cc.rect( - pointRect.x * scaleFactor, - pointRect.y * scaleFactor, - pointRect.width * scaleFactor, - pointRect.height * scaleFactor); + pointRect.x, + pointRect.y, + pointRect.width, + pointRect.height); var wide = pointRect.width; var high = pointRect.height; diff --git a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js index 72ebb85b23..5a5f1ca9ea 100644 --- a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js @@ -50,9 +50,9 @@ proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){ var node = this._node; - var locCacheCanvas = this._cacheCanvas, locScaleFactor = cc.contentScaleFactor(); - locCacheCanvas.width = 0 | (width * locScaleFactor); - locCacheCanvas.height = 0 | (height * locScaleFactor); + var locCacheCanvas = this._cacheCanvas; + locCacheCanvas.width = 0 | width; + locCacheCanvas.height = 0 | height; var texture = new cc.Texture2D(); texture.initWithElement(locCacheCanvas); @@ -86,8 +86,7 @@ proto.end = function(){ var node = this._node; - var scale = cc.contentScaleFactor(); - cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId, scale, scale); + cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId); }; proto.clearRect = function(x, y, width, height){ diff --git a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js index b272a6fdab..e35ce64b97 100644 --- a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js @@ -133,12 +133,12 @@ if(format === cc.Texture2D.PIXEL_FORMAT_A8) cc.log( "cc.RenderTexture._initWithWidthAndHeightForWebGL() : only RGB and RGBA formats are valid for a render texture;"); - var gl = cc._renderContext, locScaleFactor = cc.contentScaleFactor(); + var gl = cc._renderContext; this._fullRect = new cc.Rect(0,0, width, height); this._fullViewport = new cc.Rect(0,0, width, height); - width = 0 | (width * locScaleFactor); - height = 0 | (height * locScaleFactor); + width = 0 | width; + height = 0 | height; this._oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING); @@ -329,11 +329,11 @@ /* var size = director.getWinSizeInPixels(); // restore viewport - gl.viewport(0, 0, size.width * cc.contentScaleFactor(), size.height * cc.contentScaleFactor()); + gl.viewport(0, 0, size.width, size.height); // special viewport for 3d projection + retina display - if (director.getProjection() == cc.Director.PROJECTION_3D && cc.contentScaleFactor() != 1) { - gl.viewport((-size.width / 2), (-size.height / 2), (size.width * cc.contentScaleFactor()), (size.height * cc.contentScaleFactor())); + if (director.getProjection() == cc.Director.PROJECTION_3D) { + gl.viewport((-size.width / 2), (-size.height / 2), size.width, size.height)); } director.setProjection(director.getProjection());*/ diff --git a/cocos2d/tilemap/CCTMXLayer.js b/cocos2d/tilemap/CCTMXLayer.js index bb2a3d6309..9e7566f823 100644 --- a/cocos2d/tilemap/CCTMXLayer.js +++ b/cocos2d/tilemap/CCTMXLayer.js @@ -285,11 +285,11 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ // offset (after layer orientation is set); var offset = this._calculateLayerOffset(layerInfo.offset); - this.setPosition(cc.pointPixelsToPoints(offset)); + this.setPosition(offset); this._atlasIndexArray = []; - this.setContentSize(cc.sizePixelsToPoints(cc.size(this._layerSize.width * this._mapTileSize.width, - this._layerSize.height * this._mapTileSize.height))); + this.setContentSize(cc.size(this._layerSize.width * this._mapTileSize.width, + this._layerSize.height * this._mapTileSize.height)); this._useAutomaticVertexZ = false; this._vertexZvalue = 0; return true; @@ -344,7 +344,6 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ // tile not created yet. create it if (!tile) { var rect = this.tileset.rectForGID(gid); - rect = cc.rectPixelsToPoints(rect); tile = new _ccsg.Sprite(); tile.initWithTexture(this.texture, rect); @@ -464,7 +463,6 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ var sprite = this.getChildByTag(z); if (sprite) { var rect = this.tileset.rectForGID(gid); - rect = cc.rectPixelsToPoints(rect); sprite.setTextureRect(rect, false); if (flags != null) @@ -552,7 +550,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ ret = this._positionForHexAt(pos); break; } - return cc.pointPixelsToPoints(ret); + return ret; }, // XXX: Deprecated. For backward compatibility only // positionAt:getPositionAt, @@ -687,7 +685,6 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ _appendTileForGID:function (gid, pos) { var rect = this.tileset.rectForGID(gid); - rect = cc.rectPixelsToPoints(rect); var z = 0 | (pos.x + pos.y * this._layerSize.width); var tile = this._renderCmd._reusedTileWithRect(rect); @@ -708,7 +705,6 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ _insertTileForGID:function (gid, pos) { var rect = this.tileset.rectForGID(gid); - rect = cc.rectPixelsToPoints(rect); var z = 0 | (pos.x + pos.y * this._layerSize.width); var tile = this._renderCmd._reusedTileWithRect(rect); diff --git a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js index 6051b50e11..2cce4193c0 100644 --- a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js @@ -106,14 +106,13 @@ proto._updateCacheContext = function(size, height){ var node = this._node, locContentSize = node._contentSize, - locCanvas = this._cacheCanvas, - scaleFactor = cc.contentScaleFactor(); - locCanvas.width = 0 | (locContentSize.width * 1.5 * scaleFactor); - locCanvas.height = 0 | (locContentSize.height * 1.5 * scaleFactor); + locCanvas = this._cacheCanvas; + locCanvas.width = 0 | (locContentSize.width * 1.5); + locCanvas.height = 0 | (locContentSize.height * 1.5); //todo: need change the wrapper's height if(node.layerOrientation === cc.TMX_ORIENTATION_HEX) - this._cacheContext.setOffset(0, -node._mapTileSize.height * 0.5); //translate for hexagonal + this._cacheContext.setOffset(0, -node._mapTileSize.height * 0.5); //translate for hexagonal else this._cacheContext.setOffset(0, 0); var locTexContentSize = this._cacheTexture._contentSize; diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index 184db33703..fa9cc83a06 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -76,9 +76,6 @@ cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, off } } - if(arguments.length === 2) - rect = cc.rectPointsToPixels(rect); - offset = offset || cc.p(0, 0); originalSize = originalSize || rect; rotated = rotated || false; diff --git a/jsb/versions/jsb-polyfill-v3.5.js b/jsb/versions/jsb-polyfill-v3.5.js index 4a1e9d0476..79f02d2b36 100644 --- a/jsb/versions/jsb-polyfill-v3.5.js +++ b/jsb/versions/jsb-polyfill-v3.5.js @@ -55,9 +55,6 @@ cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, off } } - if(arguments.length === 2) - rect = cc.rectPointsToPixels(rect); - offset = cc.p(0, 0); originalSize = originalSize || rect; rotated = rotated || false; diff --git a/test/visual-tests/src/SpriteTest/SpriteTest.js b/test/visual-tests/src/SpriteTest/SpriteTest.js index cd8ffb0215..7c2109c0b1 100644 --- a/test/visual-tests/src/SpriteTest/SpriteTest.js +++ b/test/visual-tests/src/SpriteTest/SpriteTest.js @@ -4914,113 +4914,6 @@ var SpriteSkewNegativeScaleChildren = SpriteTestDemo.extend({ } }); -var DoubleSprite = _ccsg.Sprite.extend({ - HD:false, - - ctor:function (fileName) { - this._super(fileName); - //var resolutionType = texture.getResolutionType(); - //this.HD = ( resolutionType == cc.kCCResolutioniPhoneRetinaDisplay || resolutionType == kCCResolutioniPadRetinaDisplay ); - }, - - setContentSize:function (size) { - var newSize = cc.size(size.width, size.height); - // If Retina Display and Texture is in HD then scale the vertex rect - if (cc.contentScaleFactor() == 2 && !this.HD) { - newSize.width *= 2; - newSize.height *= 2; - } - this._super(newSize); - }, - _setWidth:function (value) { - // If Retina Display and Texture is in HD then scale the vertex rect - if (cc.contentScaleFactor() == 2 && !this.HD) { - value *= 2; - } - this._super(value); - }, - _setHeight:function (value) { - // If Retina Display and Texture is in HD then scale the vertex rect - if (cc.contentScaleFactor() == 2 && !this.HD) { - value *= 2; - } - this._super(value); - }, - - setVertexRect:function (rect) { - // If Retina Display and Texture is in HD then scale the vertex rect - if (cc.contentScaleFactor() == 2 && !this.HD) { - rect.width *= 2; - rect.height *= 2; - } - this._super(rect); - } -}); - -cc.defineGetterSetter(DoubleSprite.prototype, "width", DoubleSprite.prototype._getWidth, DoubleSprite.prototype._setWidth); -cc.defineGetterSetter(DoubleSprite.prototype, "height", DoubleSprite.prototype._getHeight, DoubleSprite.prototype._setHeight); - -var SpriteDoubleResolution = SpriteTestDemo.extend({ - - _title:"Sprite Double resolution", - _subtitle:"Retina Display. SD (left) should be equal to HD (right)", - - ctor:function () { - //----start52----ctor - this._super(); - - // - // LEFT: SD sprite - // - // there is no HD resolution file of grossini_dance_08. - var spriteSD = new DoubleSprite(s_grossiniDance08); - this.addChild(spriteSD); - spriteSD.x = winSize.width / 4; - spriteSD.y = winSize.height / 2; - - var child1_left = new DoubleSprite(s_grossiniDance08); - spriteSD.addChild(child1_left); - child1_left.x = -30; - child1_left.y = 0; - - var child1_right = new _ccsg.Sprite(s_pathGrossini); - spriteSD.addChild(child1_right); - child1_left.x = spriteSD.height; - child1_left.y = 0; - - // - // RIGHT: HD sprite - // - // there is an HD version of grossini.png - var spriteHD = new _ccsg.Sprite(s_pathGrossini); - this.addChild(spriteHD); - spriteHD.x = winSize.width / 4 * 3; - spriteHD.y = winSize.height / 2; - - var child2_left = new DoubleSprite(s_grossiniDance08); - spriteHD.addChild(child2_left); - child2_left.x = -30; - child2_left.y = 0; - - var child2_right = new _ccsg.Sprite(s_pathGrossini); - spriteHD.addChild(child2_right); - child2_left.x = spriteHD.height; - child2_left.y = 0; - - - // Actions - var scale = cc.scaleBy(2, 0.5); - var scale_back = scale.reverse(); - var seq = cc.sequence(scale, scale_back); - - var seq_copy = seq.clone(); - - spriteSD.runAction(seq); - spriteHD.runAction(seq_copy); - //----end52---- - } -}); - var SpriteFrameAnimationCacheFile = SpriteTestDemo.extend({ _title:"SpriteFrameAnimationCache - Load file", From 4be34aeec8bfb18f19819b66bc5a71f026b98ae8 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 23 Feb 2016 10:22:12 +0800 Subject: [PATCH 2/2] remove contentScaleFactor Redundant code --- cocos2d/core/sprites/CCSpriteFrame.js | 118 ++---------------- cocos2d/core/sprites/CCSpriteFrameCache.js | 2 +- cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js | 20 +-- cocos2d/particle/CCSGParticleSystem.js | 2 +- .../CCSGParticleSystemWebGLRenderCmd.js | 22 ++-- jsb/jsb-tex-sprite-frame.js | 2 +- 6 files changed, 31 insertions(+), 135 deletions(-) diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index d7891beb19..91c12e3445 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -90,15 +90,12 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ // the location of the sprite on rendering texture this._rect = null; - this._rectInPixels = null; // for trimming this._offset = null; - this._offsetInPixels = null; // for trimming this._originalSize = null; - this._originalSizeInPixels = null; this._rotated = false; @@ -170,34 +167,6 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this.once("load", callback, target); }, - /** - * Gets the rect of the frame in the texture. - * @method getRectInPixels - * @return {Rect} - */ - getRectInPixels: function () { - return cc.rect(this._rectInPixels); - }, - - /** - * Sets the rect of the frame in the texture. - * @method setRectInPixels - * @param {Rect} rectInPixels - */ - setRectInPixels: function (rectInPixels) { - if (!this._rectInPixels) { - this._rectInPixels = cc.rect(rectInPixels); - } else { - var rect = this._rectInPixels; - rect.x = rectInPixels.x; - rect.y = rectInPixels.y; - rect.width = rectInPixels.width; - rect.height = rectInPixels.height; - } - - this._rect = rectInPixels; - }, - /** * Returns whether the sprite frame is rotated in the texture. * @method isRotated @@ -231,66 +200,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ * @param {Rect} rect */ setRect: function (rect) { - if (!this._rect) { - this._rect = cc.rect(rect); - } else { - var locRect = this._rect; - locRect.x = rect.x; - locRect.y = rect.y; - locRect.width = rect.width; - locRect.height = rect.height; - } - this._rectInPixels = rect; - }, - - /** - * Returns the offset of the sprite frame in the texture in pixel. - * @method getOffsetInPixels - * @return {Vec2} - */ - getOffsetInPixels: function () { - return cc.v2(this._offsetInPixels); - }, - - /** - * Sets the offset of the sprite frame in the texture in pixel. - * @method setOffsetInPixels - * @param {Vec2} offsetInPixels - */ - setOffsetInPixels: function (offsetInPixels) { - if (!this._offsetInPixels) { - this._offsetInPixels = cc.v2(offsetInPixels); - } else { - this._offsetInPixels.x = offsetInPixels.x; - this._offsetInPixels.y = offsetInPixels.y; - } - - this._offset = offsetInPixels; - }, - - /** - * Returns the original size of the trimmed image. - * @method getOriginalSizeInPixels - * @return {Size} - */ - getOriginalSizeInPixels: function () { - return cc.size(this._originalSizeInPixels); - }, - - /** - * Sets the original size of the trimmed image. - * @method setOriginalSizeInPixels - * @param {Size} sizeInPixels - */ - setOriginalSizeInPixels: function (sizeInPixels) { - if (!this._originalSizeInPixels) { - this._originalSizeInPixels = cc.size(sizeInPixels); - } else { - this._originalSizeInPixels.width = sizeInPixels.width; - this._originalSizeInPixels.height = sizeInPixels.height; - } - - this._originalSize = sizeInPixels; + this._rect = rect; }, /** @@ -314,8 +224,6 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ this._originalSize.width = size.width; this._originalSize.height = size.height; } - - this._originalSizeInPixels = size; }, /** @@ -388,13 +296,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ * @param {Vec2} offsets */ setOffset: function (offsets) { - if (!this._offset) { - this._offset = cc.v2(offsets); - } else { - this._offset.x = offsets.x; - this._offset.y = offsets.y; - } - this._offsetInPixels = offsets; + this._offset = cc.v2(offsets); }, /** @@ -403,7 +305,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ * @return {SpriteFrame} */ clone: function () { - return new cc.SpriteFrame(this._textureFilename, this._rectInPixels, this._rotated, this._offsetInPixels, this._originalSizeInPixels); + return new cc.SpriteFrame(this._textureFilename, this._rect, this._rotated, this._offset, this._originalSize); }, /** @@ -424,21 +326,21 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ setTexture: function (textureOrTextureFile, rect, rotated, offset, originalSize) { if (rect) { - this.setRectInPixels(rect); + this.setRect(rect); } else { - this._rect = this._rectInPixels = null; + this._rect = null; } if (offset) { - this.setOffsetInPixels(offset); + this.setOffset(offset); } else { - this._offset = this._offsetInPixels = null; + this._offset = null; } if (originalSize) { - this.setOriginalSizeInPixels(originalSize); + this.setOriginalSize(originalSize); } else { - this._originalSize = this._originalSizeInPixels = null; + this._originalSize = null; } this._rotated = rotated || false; @@ -463,7 +365,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ }, _checkRect: function (texture) { - var rect = this._rectInPixels; + var rect = this._rect; var maxX = rect.x, maxY = rect.y; if (this._rotated) { maxX += rect.height; diff --git a/cocos2d/core/sprites/CCSpriteFrameCache.js b/cocos2d/core/sprites/CCSpriteFrameCache.js index c1e6249c2e..bbb5ec46a8 100644 --- a/cocos2d/core/sprites/CCSpriteFrameCache.js +++ b/cocos2d/core/sprites/CCSpriteFrameCache.js @@ -185,7 +185,7 @@ cc.spriteFrameCache = /** @lends cc.spriteFrameCache# */{ var locTexture = spriteFrame.getTexture(); if (locTexture.isLoaded()) { var tempElement = spriteFrame.getTexture().getHtmlElementObj(); - tempElement = _ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, spriteFrame.getRectInPixels()); + tempElement = _ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, spriteFrame.getRect()); var tempTexture = new cc.Texture2D(); tempTexture.initWithElement(tempElement); tempTexture.handleLoadedTexture(); diff --git a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js index d9d07d6347..b60438c28e 100644 --- a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js +++ b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js @@ -62,8 +62,8 @@ var texture = locTextureAtlas.texture; var textureWide = texture.getPixelWidth(); var textureHigh = texture.getPixelHeight(); - var itemWidthInPixels = node._itemWidth; - var itemHeightInPixels = node._itemHeight; + var itemWidth = node._itemWidth; + var itemHeight = node._itemHeight; if (n > locTextureAtlas.getCapacity()) cc.log("cc.LabelAtlas._updateAtlasValues(): Invalid String length"); var quads = locTextureAtlas.quads; @@ -84,15 +84,15 @@ var left, right, top, bottom; if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { // Issue #938. Don't use texStepX & texStepY - left = (2 * row * itemWidthInPixels + 1) / (2 * textureWide); - right = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide); - top = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh); - bottom = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh); + left = (2 * row * itemWidth + 1) / (2 * textureWide); + right = left + (itemWidth * 2 - 2) / (2 * textureWide); + top = (2 * col * itemHeight + 1) / (2 * textureHigh); + bottom = top + (itemHeight * 2 - 2) / (2 * textureHigh); } else { - left = row * itemWidthInPixels / textureWide; - right = left + itemWidthInPixels / textureWide; - top = col * itemHeightInPixels / textureHigh; - bottom = top + itemHeightInPixels / textureHigh; + left = row * itemWidth / textureWide; + right = left + itemWidth / textureWide; + top = col * itemHeight / textureHigh; + bottom = top + itemHeight / textureHigh; } var quad = quads[i]; var locQuadTL = quad.tl, locQuadTR = quad.tr, locQuadBL = quad.bl, locQuadBR = quad.br; diff --git a/cocos2d/particle/CCSGParticleSystem.js b/cocos2d/particle/CCSGParticleSystem.js index 7aa02fc39f..b854f8b820 100644 --- a/cocos2d/particle/CCSGParticleSystem.js +++ b/cocos2d/particle/CCSGParticleSystem.js @@ -1953,7 +1953,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ if (!spriteFrame) return; - var locOffset = spriteFrame.getOffsetInPixels(); + var locOffset = spriteFrame.getOffset(); if (locOffset.x !== 0 || locOffset.y !== 0) cc.log("_ccsg.ParticleSystem.setDisplayFrame(): QuadParticle only supports SpriteFrames with no offsets"); diff --git a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js index 8aab337140..945f4cb6e4 100644 --- a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js +++ b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js @@ -209,12 +209,6 @@ proto.initTexCoordsWithRect = function(pointRect){ var node = this._node; var texture = node.texture; - // convert to pixels coords - var rect = cc.rect( - pointRect.x, - pointRect.y, - pointRect.width, - pointRect.height); var wide = pointRect.width; var high = pointRect.height; @@ -226,15 +220,15 @@ var left, bottom, right, top; if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { - left = (rect.x * 2 + 1) / (wide * 2); - bottom = (rect.y * 2 + 1) / (high * 2); - right = left + (rect.width * 2 - 2) / (wide * 2); - top = bottom + (rect.height * 2 - 2) / (high * 2); + left = (pointRect.x * 2 + 1) / (wide * 2); + bottom = (pointRect.y * 2 + 1) / (high * 2); + right = left + (pointRect.width * 2 - 2) / (wide * 2); + top = bottom + (pointRect.height * 2 - 2) / (high * 2); } else { - left = rect.x / wide; - bottom = rect.y / high; - right = left + rect.width / wide; - top = bottom + rect.height / high; + left = pointRect.x / wide; + bottom = pointRect.y / high; + right = left + pointRect.width / wide; + top = bottom + pointRect.height / high; } // Important. Texture in cocos2d are inverted, so the Y component should be inverted diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index fa9cc83a06..79a3952a3f 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -139,7 +139,7 @@ cc.SpriteFrame.prototype._deserialize = function (data, handle) { this.initWithTexture(null, rect, rotated, offset, size, textureUuid); }; cc.SpriteFrame.prototype._checkRect = function (texture) { - var rect = this.getRectInPixels(); + var rect = this.getRect(); var maxX = rect.x, maxY = rect.y; if (this._rotated) { maxX += rect.height;