From 6648543446a281b60617485ce9718bf9538db0e1 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 1 Mar 2017 17:11:51 +0000 Subject: [PATCH] New features added. --- v3/src/checksum.js | 2 +- v3/src/gameobjects/bitmaptext/BitmapText.js | 24 ++++++++++- .../bitmaptext/BitmapTextCanvasRenderer.js | 41 ++++++++++++++----- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 761cb9e1f..69c9ae09a 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '24668b80-fe14-11e6-9463-35f4273cae70' +build: 'e143e9e0-fe97-11e6-b242-774fc1dcf72c' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/bitmaptext/BitmapText.js b/v3/src/gameobjects/bitmaptext/BitmapText.js index 64d992fb4..4e2c87b3a 100644 --- a/v3/src/gameobjects/bitmaptext/BitmapText.js +++ b/v3/src/gameobjects/bitmaptext/BitmapText.js @@ -28,11 +28,33 @@ var BitmapText = new Class({ this.fontData = this.state.sys.cache.bitmapFont.get(font); this.text = text; - + this.fontSize = size; + // Setting these will enable the Size component to work + // then anchorX etc will work too + // this.frame.realWidth = 0; + // this.frame.realHeight = 0; + + this.displayCallback; + this.setTexture(font); this.setPosition(x, y); + }, + + setDisplayCallback: function (callback) + { + this.displayCallback = callback; + + return this; + }, + + setText: function (text) + { + // this._text = text; + // this.dirty = true; + + return this; } }); diff --git a/v3/src/gameobjects/bitmaptext/BitmapTextCanvasRenderer.js b/v3/src/gameobjects/bitmaptext/BitmapTextCanvasRenderer.js index f30a43ae1..3bb630cf5 100644 --- a/v3/src/gameobjects/bitmaptext/BitmapTextCanvasRenderer.js +++ b/v3/src/gameobjects/bitmaptext/BitmapTextCanvasRenderer.js @@ -10,15 +10,14 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, 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 srcX = src.x; - var srcY = src.y; - var xAdvance = 0; var yAdvance = 0; @@ -43,8 +42,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, var textureX = textureFrame.cutX; var textureY = textureFrame.cutY; - var scaleX = src.scaleX * (src.fontSize / src.fontData.size); - var scaleY = src.scaleY * (src.fontSize / src.fontData.size); + var rotation = 0; + var scale = (src.fontSize / src.fontData.size); // Blend Mode if (renderer.currentBlendMode !== src.blendMode) @@ -66,8 +65,17 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, 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) @@ -92,8 +100,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, glyphW = glyph.width; glyphH = glyph.height; - x = srcX + indexCount + glyph.xOffset + xAdvance; - y = srcY + glyph.yOffset + yAdvance; + x = indexCount + glyph.xOffset + xAdvance; + y = glyph.yOffset + yAdvance; if (lastGlyph !== null) { @@ -101,15 +109,26 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, x += (kerningOffset !== undefined) ? kerningOffset : 0; } - x *= scaleX; - y *= scaleY; + 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.scale(scaleX, scaleY); + ctx.rotate(rotation); + ctx.scale(scale, scale); ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH); ctx.restore(); @@ -118,6 +137,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, lastGlyph = glyph; lastCharCode = charCode; } + + ctx.restore(); }; module.exports = BitmapTextCanvasRenderer;