2017-03-08 22:36:53 +00:00
|
|
|
var Class = require('../../../utils/Class');
|
|
|
|
var GameObject = require('../../GameObject');
|
|
|
|
var Components = require('../../../components');
|
2017-03-01 00:16:35 +00:00
|
|
|
var Render = require('./BitmapTextRender');
|
2017-03-08 22:36:53 +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-28 18:16:02 +00:00
|
|
|
Components.RenderPass,
|
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;
|
|
|
|
|
|
|
|
this.setTexture(font);
|
|
|
|
this.setPosition(x, y);
|
2017-03-20 19:10:44 +00:00
|
|
|
this.setOrigin(0, 0);
|
2017-03-28 18:16:02 +00:00
|
|
|
this.initRenderPassComponent();
|
2017-03-01 17:11:51 +00:00
|
|
|
},
|
|
|
|
|
2017-03-03 01:41:33 +00:00
|
|
|
setFontSize: function (size)
|
|
|
|
{
|
|
|
|
this.fontSize = size;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-03-01 17:11:51 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2017-03-03 01:41:33 +00:00
|
|
|
// {
|
|
|
|
// local: {
|
|
|
|
// x,
|
|
|
|
// y,
|
|
|
|
// width,
|
|
|
|
// height
|
|
|
|
// },
|
|
|
|
// global: {
|
|
|
|
// x,
|
|
|
|
// y,
|
|
|
|
// width,
|
|
|
|
// height
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2017-03-02 04:00:39 +00:00
|
|
|
getTextBounds: function ()
|
|
|
|
{
|
2017-03-03 01:41:33 +00:00
|
|
|
// local = the BitmapText based on fontSize and 0x0 coords
|
|
|
|
// global = the BitmapText, taking into account scale and world position
|
2017-03-02 04:00:39 +00:00
|
|
|
|
2017-03-03 01:41:33 +00:00
|
|
|
return GetBitmapTextSize(this);
|
2017-03-01 00:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = BitmapText;
|