var Class = require('../../../utils/Class'); var Components = require('../../components'); var GameObject = require('../../GameObject'); var GetBitmapTextSize = require('../GetBitmapTextSize'); var Render = require('./DynamicBitmapTextRender'); var DynamicBitmapText = new Class({ Extends: GameObject, Mixins: [Components.Alpha, Components.BlendMode, Components.Depth, Components.Origin, Components.Pipeline, Components.ScrollFactor, Components.Texture, Components.Tint, Components.Transform, Components.Visible, Render] , initialize: function DynamicBitmapText(scene, x, y, font, text, size){ if (text === undefined) { text = ''; } GameObject.call(this, scene, 'DynamicBitmapText'); this.font = font; var entry = this.scene.sys.cache.bitmapFont.get(font); this.fontData = entry.data; _AN_Write_text('text', this, false , (Array.isArray(text))? text.join('\n'): text); this.fontSize = size || this.fontData.size; this.letterSpacing = 0; this.setTexture(entry.texture, entry.frame); this.setPosition(x, y); this.setOrigin(0, 0); this.initPipeline('TextureTintPipeline'); this._bounds = this.getTextBounds(); this.scrollX = 0; this.scrollY = 0; this.cropWidth = 0; this.cropHeight = 0; this.displayCallback; } , setSize: function (width, height){ this.cropWidth = width; this.cropHeight = height; return this; } , setDisplayCallback: function (callback){ this.displayCallback = callback; return this; } , setFontSize: function (size){ this.fontSize = size; return this; } , setText: function (value){ if (!value && value !== 0) { value = ''; } if (Array.isArray(value)) { value = value.join('\n'); } if (value !== this.text) { _AN_Write_text('text', this, false , value.toString()); this.updateDisplayOrigin(); } return this; } , setScrollX: function (value){ this.scrollX = value; return this; } , setScrollY: function (value){ this.scrollY = value; return this; } , getTextBounds: function (round){ this._bounds = GetBitmapTextSize(this, round); return this._bounds; } , width: { get: function (){ this.getTextBounds(false ); return this._bounds.global.width; } } , height: { get: function (){ this.getTextBounds(false ); return this._bounds.global.height; } } , toJSON: function (){ var out = Components.ToJSON(this); var data = { font: this.font, text: this.text, fontSize: this.fontSize} ; out.data = data; return out; } } ); module.exports = DynamicBitmapText;