2017-03-01 00:16:35 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var GameObject = require('../GameObject');
|
|
|
|
var Components = require('../../components');
|
|
|
|
var Render = require('./BitmapTextRender');
|
2017-03-02 04:00:39 +00:00
|
|
|
var GetBitmapTextSize = require('./GetBitmapTextSize');
|
2017-03-01 00:16:35 +00:00
|
|
|
|
|
|
|
var BitmapText = new Class({
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
2017-03-02 04:00:39 +00:00
|
|
|
Components.Origin,
|
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
|
|
|
Components.Transform,
|
2017-03-01 00:16:35 +00:00
|
|
|
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;
|
2017-03-01 17:11:51 +00:00
|
|
|
|
2017-03-01 00:16:35 +00:00
|
|
|
this.fontSize = size;
|
|
|
|
|
2017-03-01 17:11:51 +00:00
|
|
|
this.displayCallback;
|
|
|
|
|
2017-03-01 00:16:35 +00:00
|
|
|
this.setTexture(font);
|
|
|
|
this.setPosition(x, y);
|
2017-03-01 17:11:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setDisplayCallback: function (callback)
|
|
|
|
{
|
|
|
|
this.displayCallback = callback;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setText: function (text)
|
|
|
|
{
|
2017-03-02 04:00:39 +00:00
|
|
|
this.text = text;
|
2017-03-01 17:11:51 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-02 04:00:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getTextBounds: function ()
|
|
|
|
{
|
|
|
|
var size = GetBitmapTextSize(this);
|
|
|
|
|
|
|
|
return { x: this.x + size.x, y: this.y + size.y, width: size.width, height: size.height };
|
2017-03-01 00:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = BitmapText;
|