mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
BitmapText can take a contents array now. Also fixed scroll rect.
This commit is contained in:
parent
798ffa9c16
commit
3852c9c359
4 changed files with 35 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'ae3fbaf0-4bdc-11e7-8d01-0d1ecc83299a'
|
||||
build: 'b5751ca0-4be3-11e7-b9b3-d158ff787407'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -13,7 +13,6 @@ var DynamicBitmapText = new Class({
|
|||
Components.BlendMode,
|
||||
Components.Origin,
|
||||
Components.RenderTarget,
|
||||
Components.Size,
|
||||
Components.Texture,
|
||||
Components.Transform,
|
||||
Components.Visible,
|
||||
|
@ -31,14 +30,15 @@ var DynamicBitmapText = new Class({
|
|||
|
||||
this.fontData = this.state.sys.cache.bitmapFont.get(font);
|
||||
|
||||
this.text = text;
|
||||
this.text = (Array.isArray(text)) ? text.join('\n') : text;
|
||||
|
||||
this.fontSize = size || this.fontData.size;
|
||||
|
||||
this._scrollX = 0;
|
||||
this._scrollY = 0;
|
||||
this._maxWidth = 0;
|
||||
this._maxHeight = 0;
|
||||
this.scrollX = 0;
|
||||
this.scrollY = 0;
|
||||
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
|
||||
this.displayCallback;
|
||||
|
||||
|
@ -46,6 +46,14 @@ var DynamicBitmapText = new Class({
|
|||
this.setPosition(x, y);
|
||||
},
|
||||
|
||||
setSize: function (width, height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setDisplayCallback: function (callback)
|
||||
{
|
||||
this.displayCallback = callback;
|
||||
|
@ -67,30 +75,16 @@ var DynamicBitmapText = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
setMaxWidth: function (value)
|
||||
{
|
||||
this._maxWidth = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setMaxHeight: function (value)
|
||||
{
|
||||
this._maxHeight = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setScrollX: function (value)
|
||||
{
|
||||
this._scrollX = value;
|
||||
this.scrollX = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setScrollY: function (value)
|
||||
{
|
||||
this._scrollY = value;
|
||||
this.scrollY = value;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
|
@ -70,8 +70,14 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
|
|||
ctx.rotate(src.rotation);
|
||||
ctx.scale(src.scaleX, src.scaleY);
|
||||
|
||||
var currentX;
|
||||
var currentY;
|
||||
if (src.width > 0 && src.height > 0)
|
||||
{
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.rect(0, 0, src.width, src.height);
|
||||
ctx.clip();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
for (var index = 0; index < textLength; ++index)
|
||||
{
|
||||
|
@ -103,8 +109,10 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
|
|||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = indexCount + glyph.xOffset + xAdvance;
|
||||
y = glyph.yOffset + yAdvance;
|
||||
x = (indexCount + glyph.xOffset + xAdvance) - src.scrollX;
|
||||
y = (glyph.yOffset + yAdvance) - src.scrollY;
|
||||
|
||||
// This could be optimized so that it doesn't even bother drawing it if the x/y is out of range
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
|
@ -122,9 +130,6 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
|
|||
rotation = output.rotation;
|
||||
}
|
||||
|
||||
// Scroll clipping
|
||||
x -= src._scrollX;
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
|
@ -149,6 +154,11 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
|
|||
lastCharCode = charCode;
|
||||
}
|
||||
|
||||
if (src.width > 0 && src.height > 0)
|
||||
{
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ var BitmapText = new Class({
|
|||
this.font = font;
|
||||
this.fontData = this.state.sys.cache.bitmapFont.get(font);
|
||||
|
||||
this.text = text;
|
||||
this.text = (Array.isArray(text)) ? text.join('\n') : text;
|
||||
|
||||
this.fontSize = size || this.fontData.size;
|
||||
|
||||
|
|
Loading…
Reference in a new issue