phaser/v3/src/gameobjects/bitmaptext/BitmapText.js

89 lines
1.8 KiB
JavaScript
Raw Normal View History

var Class = require('../../utils/Class');
var GameObject = require('../GameObject');
var Components = require('../../components');
var Render = require('./BitmapTextRender');
var GetBitmapTextSize = require('./GetBitmapTextSize');
var BitmapText = new Class({
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.Origin,
Components.Size,
Components.Texture,
Components.Transform,
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
this.fontSize = size;
2017-03-01 17:11:51 +00:00
this.displayCallback;
this.setTexture(font);
this.setPosition(x, y);
2017-03-01 17:11:51 +00:00
},
setDisplayCallback: function (callback)
{
this.displayCallback = callback;
return this;
},
setFontSize: function (size)
{
this.fontSize = size;
return this;
},
2017-03-01 17:11:51 +00:00
setText: function (text)
{
this.text = text;
2017-03-01 17:11:51 +00:00
return this;
},
// {
// local: {
// x,
// y,
// width,
// height
// },
// global: {
// x,
// y,
// width,
// height
// }
// }
getTextBounds: function ()
{
// local = the BitmapText based on fontSize and 0x0 coords
// global = the BitmapText, taking into account scale and world position
return GetBitmapTextSize(this);
}
});
module.exports = BitmapText;