Merge pull request #107 from krzysztof-o/master
BitmapText docs update and new line character
This commit is contained in:
commit
1d06c7d4db
2 changed files with 13 additions and 13 deletions
|
@ -3,19 +3,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Text Object will create a line(s) of text using bitmap font
|
* A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n"
|
||||||
* You can generate the fnt files using
|
* You can generate the fnt files using
|
||||||
* http://www.angelcode.com/products/bmfont/ for windows of
|
* http://www.angelcode.com/products/bmfont/ for windows or
|
||||||
* http://www.bmglyph.com/ for mac.
|
* http://www.bmglyph.com/ for mac.
|
||||||
* @class BitmapText
|
* @class BitmapText
|
||||||
* @extends DisplayObjectContainer
|
* @extends DisplayObjectContainer
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {String} text The copy that you would like the text to display
|
* @param {String} text The copy that you would like the text to display
|
||||||
* @param {Object} [style] The style parameters
|
* @param {Object} style The style parameters
|
||||||
* @param {String} [style.font] default is "20pt Arial" The size and bitmap font id (must have loaded previously)
|
* @param {String} style.font The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
|
||||||
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
||||||
*/
|
*/
|
||||||
//* @param {Object} [style.font="bold 20pt Arial"] The style and size of the font
|
|
||||||
PIXI.BitmapText = function(text, style)
|
PIXI.BitmapText = function(text, style)
|
||||||
{
|
{
|
||||||
PIXI.DisplayObjectContainer.call(this);
|
PIXI.DisplayObjectContainer.call(this);
|
||||||
|
@ -33,7 +32,7 @@ PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the copy for the text object
|
* Set the copy for the text object
|
||||||
* @methos setText
|
* @method setText
|
||||||
* @param {String} text The copy that you would like the text to display
|
* @param {String} text The copy that you would like the text to display
|
||||||
*/
|
*/
|
||||||
PIXI.BitmapText.prototype.setText = function(text)
|
PIXI.BitmapText.prototype.setText = function(text)
|
||||||
|
@ -45,8 +44,8 @@ PIXI.BitmapText.prototype.setText = function(text)
|
||||||
/**
|
/**
|
||||||
* Set the style of the text
|
* Set the style of the text
|
||||||
* @method setStyle
|
* @method setStyle
|
||||||
* @param {Object} [style] The style parameters
|
* @param {Object} style The style parameters
|
||||||
* @param {Object} style.font The style and size of the font. If font size is not specified, it uses default bitmap font size. Font name is required
|
* @param {String} style.font The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
|
||||||
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
||||||
*/
|
*/
|
||||||
PIXI.BitmapText.prototype.setStyle = function(style)
|
PIXI.BitmapText.prototype.setStyle = function(style)
|
||||||
|
@ -79,7 +78,7 @@ PIXI.BitmapText.prototype.updateText = function()
|
||||||
for(var i = 0; i < this.text.length; i++)
|
for(var i = 0; i < this.text.length; i++)
|
||||||
{
|
{
|
||||||
var charCode = this.text.charCodeAt(i);
|
var charCode = this.text.charCodeAt(i);
|
||||||
if(charCode == "\n".charCodeAt(0))
|
if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i)))
|
||||||
{
|
{
|
||||||
lineWidths.push(pos.x);
|
lineWidths.push(pos.x);
|
||||||
maxLineWidth = Math.max(maxLineWidth, pos.x);
|
maxLineWidth = Math.max(maxLineWidth, pos.x);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Text Object will create a line(s) of text to split a line you can use "\n"
|
* A Text Object will create a line(s) of text. To split a line you can use "\n", "\r" or "\r\n"
|
||||||
* @class Text
|
* @class Text
|
||||||
* @extends Sprite
|
* @extends Sprite
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -54,7 +54,7 @@ PIXI.Text.prototype.setStyle = function(style)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the copy for the text object. To split a line you can use "\n"
|
* Set the copy for the text object. To split a line you can use "\n"
|
||||||
* @methos setText
|
* @method setText
|
||||||
* @param {String} text The copy that you would like the text to display
|
* @param {String} text The copy that you would like the text to display
|
||||||
*/
|
*/
|
||||||
PIXI.Sprite.prototype.setText = function(text)
|
PIXI.Sprite.prototype.setText = function(text)
|
||||||
|
@ -72,7 +72,7 @@ PIXI.Text.prototype.updateText = function()
|
||||||
this.context.font = this.style.font;
|
this.context.font = this.style.font;
|
||||||
|
|
||||||
//split text into lines
|
//split text into lines
|
||||||
var lines = this.text.split("\n");
|
var lines = this.text.split(/(?:\r\n|\r|\n)/);
|
||||||
|
|
||||||
//calculate text width
|
//calculate text width
|
||||||
var lineWidths = [];
|
var lineWidths = [];
|
||||||
|
@ -154,9 +154,10 @@ PIXI.Text.prototype.updateTransform = function()
|
||||||
PIXI.Sprite.prototype.updateTransform.call(this);
|
PIXI.Sprite.prototype.updateTransform.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* http://stackoverflow.com/users/34441/ellisbben
|
* http://stackoverflow.com/users/34441/ellisbben
|
||||||
* great solution to the problem!
|
* great solution to the problem!
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
PIXI.Text.prototype.determineFontHeight = function(fontStyle)
|
PIXI.Text.prototype.determineFontHeight = function(fontStyle)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue