Added scroll offset

This commit is contained in:
Richard Davey 2017-06-08 00:55:54 +01:00
parent da0ddeab54
commit 798ffa9c16
2 changed files with 40 additions and 2 deletions

View file

@ -25,7 +25,6 @@ var DynamicBitmapText = new Class({
function DynamicBitmapText (state, x, y, font, text, size, align) function DynamicBitmapText (state, x, y, font, text, size, align)
{ {
if (text === undefined) { text = ''; } if (text === undefined) { text = ''; }
if (size === undefined) { size = 32; }
if (align === undefined) { align = 'left'; } if (align === undefined) { align = 'left'; }
GameObject.call(this, state, 'DynamicBitmapText'); GameObject.call(this, state, 'DynamicBitmapText');
@ -34,7 +33,12 @@ var DynamicBitmapText = new Class({
this.text = text; this.text = text;
this.fontSize = size; this.fontSize = size || this.fontData.size;
this._scrollX = 0;
this._scrollY = 0;
this._maxWidth = 0;
this._maxHeight = 0;
this.displayCallback; this.displayCallback;
@ -63,6 +67,34 @@ var DynamicBitmapText = new Class({
return this; return this;
}, },
setMaxWidth: function (value)
{
this._maxWidth = value;
return this;
},
setMaxHeight: function (value)
{
this._maxHeight = value;
return this;
},
setScrollX: function (value)
{
this._scrollX = value;
return this;
},
setScrollY: function (value)
{
this._scrollY = value;
return this;
},
// { // {
// local: { // local: {
// x, // x,

View file

@ -70,6 +70,9 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
ctx.rotate(src.rotation); ctx.rotate(src.rotation);
ctx.scale(src.scaleX, src.scaleY); ctx.scale(src.scaleX, src.scaleY);
var currentX;
var currentY;
for (var index = 0; index < textLength; ++index) for (var index = 0; index < textLength; ++index)
{ {
// Reset the scale (in case the callback changed it) // Reset the scale (in case the callback changed it)
@ -119,6 +122,9 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
rotation = output.rotation; rotation = output.rotation;
} }
// Scroll clipping
x -= src._scrollX;
x *= scale; x *= scale;
y *= scale; y *= scale;