From 7eeb8d5d301b0e6bdeac71004d8bacc4733fa3c1 Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Wed, 8 Mar 2017 20:49:44 -0300 Subject: [PATCH] transform checks for setter functions also removed old bitmap text --- v3/src/components/Transform.js | 10 +- v3/src/gameobjects/_bitmaptext/BitmapText.js | 88 ----------- .../_bitmaptext/BitmapTextCanvasRenderer.js | 149 ------------------ .../_bitmaptext/BitmapTextFactory.js | 20 --- .../_bitmaptext/BitmapTextRender.js | 6 - .../_bitmaptext/BitmapTextWebGLRenderer.js | 138 ---------------- v3/src/gameobjects/graphics/Graphics.js | 2 +- 7 files changed, 6 insertions(+), 407 deletions(-) delete mode 100644 v3/src/gameobjects/_bitmaptext/BitmapText.js delete mode 100644 v3/src/gameobjects/_bitmaptext/BitmapTextCanvasRenderer.js delete mode 100644 v3/src/gameobjects/_bitmaptext/BitmapTextFactory.js delete mode 100644 v3/src/gameobjects/_bitmaptext/BitmapTextRender.js delete mode 100644 v3/src/gameobjects/_bitmaptext/BitmapTextWebGLRenderer.js diff --git a/v3/src/components/Transform.js b/v3/src/components/Transform.js index 2f1f3cffc..61b69f8eb 100644 --- a/v3/src/components/Transform.js +++ b/v3/src/components/Transform.js @@ -96,15 +96,15 @@ var Transform = { { if (y === undefined) { y = x; } - this.x = x; - this.y = y; + this.x = (x ? x : 0.0); + this.y = (y ? y : 0.0); return this; }, setRotation: function (radians) { - this.rotation = radians; + this.rotation = (radians ? radians : 0.0); return this; }, @@ -114,8 +114,8 @@ var Transform = { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } - this.scaleX = x; - this.scaleY = y; + this.scaleX = (x ? x : 0.0); + this.scaleY = (y ? y : 0.0); return this; } diff --git a/v3/src/gameobjects/_bitmaptext/BitmapText.js b/v3/src/gameobjects/_bitmaptext/BitmapText.js deleted file mode 100644 index d9128af42..000000000 --- a/v3/src/gameobjects/_bitmaptext/BitmapText.js +++ /dev/null @@ -1,88 +0,0 @@ -var Class = require('../../utils/Class'); -var GameObject = require('../GameObject'); -var Components = require('../../components'); -var Render = require('./BitmapTextRender'); -var GetBitmapTextSize = require('./GetBitmapTextSize'); - -var BitmapText = new Class({ - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Origin, - Components.Size, - Components.Texture, - Components.Transform, - Components.Visible, - Render - ], - - initialize: - - function BitmapText (state, x, y, font, text, size, align) - { - if (text === undefined) { text = ''; } - if (size === undefined) { size = 32; } - if (align === undefined) { align = 'left'; } - - GameObject.call(this, state); - - this.fontData = this.state.sys.cache.bitmapFont.get(font); - - this.text = text; - - this.fontSize = size; - - this.displayCallback; - - this.setTexture(font); - this.setPosition(x, y); - }, - - setDisplayCallback: function (callback) - { - this.displayCallback = callback; - - return this; - }, - - setFontSize: function (size) - { - this.fontSize = size; - - return this; - }, - - setText: function (text) - { - this.text = text; - - return this; - }, - - // { - // local: { - // x, - // y, - // width, - // height - // }, - // global: { - // x, - // y, - // width, - // height - // } - // } - - getTextBounds: function () - { - // local = the BitmapText based on fontSize and 0x0 coords - // global = the BitmapText, taking into account scale and world position - - return GetBitmapTextSize(this); - } - -}); - -module.exports = BitmapText; diff --git a/v3/src/gameobjects/_bitmaptext/BitmapTextCanvasRenderer.js b/v3/src/gameobjects/_bitmaptext/BitmapTextCanvasRenderer.js deleted file mode 100644 index 5c52da79f..000000000 --- a/v3/src/gameobjects/_bitmaptext/BitmapTextCanvasRenderer.js +++ /dev/null @@ -1,149 +0,0 @@ -var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera) -{ - var text = src.text; - var textLength = text.length; - - if (this.renderMask !== this.renderFlags || textLength === 0) - { - return; - } - - var textureFrame = src.frame; - - var displayCallback = src.displayCallback; - - var cameraScrollX = camera.scrollX; - var cameraScrollY = camera.scrollY; - - var chars = src.fontData.chars; - var lineHeight = src.fontData.lineHeight; - - var xAdvance = 0; - var yAdvance = 0; - - var indexCount = 0; - var charCode = 0; - - var glyph = null; - var glyphX = 0; - var glyphY = 0; - var glyphW = 0; - var glyphH = 0; - - var x = 0; - var y = 0; - - var lastGlyph = null; - var lastCharCode = 0; - - var ctx = renderer.currentContext; - var image = src.frame.source.image; - - var textureX = textureFrame.cutX; - var textureY = textureFrame.cutY; - - var rotation = 0; - var scale = (src.fontSize / src.fontData.size); - - // Blend Mode - if (renderer.currentBlendMode !== src.blendMode) - { - renderer.currentBlendMode = src.blendMode; - ctx.globalCompositeOperation = renderer.blendModes[src.blendMode]; - } - - // Alpha - if (renderer.currentAlpha !== src.alpha) - { - renderer.currentAlpha = src.alpha; - ctx.globalAlpha = src.alpha; - } - - // Smoothing - if (renderer.currentScaleMode !== src.scaleMode) - { - renderer.currentScaleMode = src.scaleMode; - } - - ctx.save(); - ctx.translate(src.x, src.y); - ctx.rotate(src.rotation); - ctx.scale(src.scaleX, src.scaleY); - - for (var index = 0; index < textLength; ++index) - { - // Reset the scale (in case the callback changed it) - scale = (src.fontSize / src.fontData.size); - rotation = 0; - - charCode = text.charCodeAt(index); - - if (charCode === 10) - { - xAdvance = 0; - indexCount = 0; - yAdvance += lineHeight; - lastGlyph = null; - continue; - } - - glyph = chars[charCode]; - - if (!glyph) - { - continue; - } - - glyphX = textureX + glyph.x; - glyphY = textureY + glyph.y; - - glyphW = glyph.width; - glyphH = glyph.height; - - x = indexCount + glyph.xOffset + xAdvance; - y = glyph.yOffset + yAdvance; - - if (lastGlyph !== null) - { - var kerningOffset = glyph.kerning[lastCharCode]; - x += (kerningOffset !== undefined) ? kerningOffset : 0; - } - - if (displayCallback) - { - var output = displayCallback({ index: index, charCode: charCode, x: x, y: y, scale: scale, rotation: 0 }); - - x = output.x; - y = output.y; - scale = output.scale; - rotation = output.rotation; - } - - x *= scale; - y *= scale; - - x -= cameraScrollX; - y -= cameraScrollY; - - ctx.save(); - ctx.translate(x, y); - ctx.rotate(rotation); - ctx.scale(scale, scale); - - // ctx.fillStyle = 'rgba(0,255,0,0.2)'; - // ctx.fillRect(0, 0, glyphW, glyphH); - - ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH); - - ctx.restore(); - - xAdvance += glyph.xAdvance; - indexCount += 1; - lastGlyph = glyph; - lastCharCode = charCode; - } - - ctx.restore(); -}; - -module.exports = BitmapTextCanvasRenderer; diff --git a/v3/src/gameobjects/_bitmaptext/BitmapTextFactory.js b/v3/src/gameobjects/_bitmaptext/BitmapTextFactory.js deleted file mode 100644 index fc164ab7b..000000000 --- a/v3/src/gameobjects/_bitmaptext/BitmapTextFactory.js +++ /dev/null @@ -1,20 +0,0 @@ -var BitmapText = require('./BitmapText'); -var FactoryContainer = require('../../FactoryContainer'); - -var BitmapTextFactory = { - - KEY: 'bitmapText', - - add: function (x, y, font, text, size, align) - { - return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align)); - }, - - make: function (x, y, font, text, size, align) - { - return new BitmapText(this.state, x, y, font, text, size, align); - } - -}; - -module.exports = FactoryContainer.register(BitmapTextFactory); diff --git a/v3/src/gameobjects/_bitmaptext/BitmapTextRender.js b/v3/src/gameobjects/_bitmaptext/BitmapTextRender.js deleted file mode 100644 index 1a6604fe0..000000000 --- a/v3/src/gameobjects/_bitmaptext/BitmapTextRender.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - - renderCanvas: require('./BitmapTextCanvasRenderer'), - renderWebGL: require('./BitmapTextWebGLRenderer') - -}; diff --git a/v3/src/gameobjects/_bitmaptext/BitmapTextWebGLRenderer.js b/v3/src/gameobjects/_bitmaptext/BitmapTextWebGLRenderer.js deleted file mode 100644 index 4c990da22..000000000 --- a/v3/src/gameobjects/_bitmaptext/BitmapTextWebGLRenderer.js +++ /dev/null @@ -1,138 +0,0 @@ -var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage, camera) -{ - if (this.renderMask !== this.renderFlags) - { - return; - } - - var textureFrame = src.frame; - var cameraMatrix = camera.matrix.matrix; - var a = cameraMatrix[0]; - var b = cameraMatrix[1]; - var c = cameraMatrix[2]; - var d = cameraMatrix[3]; - var e = cameraMatrix[4]; - var f = cameraMatrix[5]; - var cameraScrollX = camera.scrollX; - var cameraScrollY = camera.scrollY; - var text = src.text; - var textLength = text.length; - var chars = src.fontData.chars; - var lineHeight = src.fontData.lineHeight; - var blitterBatch = renderer.blitterBatch; - var alpha = src.alpha; - var vertexDataBuffer = blitterBatch.vertexDataBuffer; - var vertexBuffer = vertexDataBuffer.floatView; - var vertexOffset = 0; - var srcX = src.x; - var srcY = src.y; - var textureData = src.texture.source[textureFrame.sourceIndex]; - var textureX = textureFrame.cutX; - var textureY = textureFrame.cutY; - var textureWidth = textureData.width; - var textureHeight = textureData.height; - var texture = textureData.glTexture; - var xAdvance = 0; - var yAdvance = 0; - var indexCount = 0; - var charCode = 0; - var glyph = null; - var glyphX = 0; - var glyphY = 0; - var glyphW = 0; - var glyphH = 0; - var x = 0; - var y = 0; - var xw = 0; - var yh = 0; - var tx = 0; - var ty = 0; - var txw = 0; - var tyh = 0; - var umin = 0; - var umax = 0; - var vmin = 0; - var vmax = 0; - var lastGlyph = null; - var lastCharCode = 0; - - for (var index = 0; index < textLength; ++index) - { - charCode = text.charCodeAt(index); - if (charCode === 10) - { - xAdvance = 0; - indexCount = 0; - yAdvance += lineHeight; - lastGlyph = null; - continue; - } - - glyph = chars[charCode]; - if (!glyph) - { - continue; - } - - glyphX = textureX + glyph.x; - glyphY = textureY + glyph.y; - glyphW = glyph.width; - glyphH = glyph.height; - x = (srcX + indexCount + glyph.xOffset + xAdvance) - cameraScrollX; - y = (srcY + glyph.yOffset + yAdvance) - cameraScrollY; - - if (lastGlyph !== null) - { - var kerningOffset = glyph.kerning[lastCharCode]; - x += (kerningOffset !== undefined) ? kerningOffset : 0; - } - - xw = x + glyphW; - yh = y + glyphH; - tx = x * a + y * c + e; - ty = x * b + y * d + f; - txw = xw * a + yh * c + e; - tyh = xw * b + yh * d + f; - umin = glyphX / textureWidth; - umax = (glyphX + glyphW) / textureWidth; - vmin = glyphY / textureHeight; - vmax = (glyphY + glyphH) / textureHeight; - - if (blitterBatch.elementCount >= blitterBatch.maxParticles) - { - blitterBatch.flush(); - } - - renderer.setBatch(blitterBatch, texture); - vertexOffset = vertexDataBuffer.allocate(20); - blitterBatch.elementCount += 6; - - vertexBuffer[vertexOffset++] = tx; - vertexBuffer[vertexOffset++] = ty; - vertexBuffer[vertexOffset++] = umin; - vertexBuffer[vertexOffset++] = vmin; - vertexBuffer[vertexOffset++] = alpha; - vertexBuffer[vertexOffset++] = tx; - vertexBuffer[vertexOffset++] = tyh; - vertexBuffer[vertexOffset++] = umin; - vertexBuffer[vertexOffset++] = vmax; - vertexBuffer[vertexOffset++] = alpha; - vertexBuffer[vertexOffset++] = txw; - vertexBuffer[vertexOffset++] = tyh; - vertexBuffer[vertexOffset++] = umax; - vertexBuffer[vertexOffset++] = vmax; - vertexBuffer[vertexOffset++] = alpha; - vertexBuffer[vertexOffset++] = txw; - vertexBuffer[vertexOffset++] = ty; - vertexBuffer[vertexOffset++] = umax; - vertexBuffer[vertexOffset++] = vmin; - vertexBuffer[vertexOffset++] = alpha; - - xAdvance += glyph.xAdvance; - indexCount += 1; - lastGlyph = glyph; - lastCharCode = charCode; - } -}; - -module.exports = BitmapTextWebGLRenderer; diff --git a/v3/src/gameobjects/graphics/Graphics.js b/v3/src/gameobjects/graphics/Graphics.js index 8b42648ae..c01554004 100644 --- a/v3/src/gameobjects/graphics/Graphics.js +++ b/v3/src/gameobjects/graphics/Graphics.js @@ -108,8 +108,8 @@ var Graphics = new Class({ { this.beginPath(); this.arc(x, y, radius, 0, MATH_CONST.PI2); - this.strokePath(); this.closePath(); + this.strokePath(); }, strokeRect: function (x, y, width, height)