diff --git a/examples/wip/bitmaptext2.js b/examples/wip/bitmaptext2.js index 441b2010..56c01508 100644 --- a/examples/wip/bitmaptext2.js +++ b/examples/wip/bitmaptext2.js @@ -3,39 +3,36 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p function preload() { - game.load.image('font', 'assets/fonts/gold_font.png'); + game.load.image('goldFont', 'assets/fonts/gold_font.png'); + game.load.image('bluePink', 'assets/fonts/bluepink_font.png'); } -var font; +var font1; +var font2; function create() { - // text = game.add.bitmapText(100, 100, 'carrier', 'Phaser and Pixi\nrocking!', 32); + font1 = game.add.bitmapFont(game.world.centerX, 96, 'goldFont', 16, 16, "! :() ,?." + Phaser.BitmapFont.TEXT_SET10, 20, 0, 0); + font1.text = "phaser brings you retro style bitmap fonts"; + font1.anchor.set(0.5); - font = new Phaser.BitmapFont(game, 'font', 16, 16, "! :() ,?." + Phaser.BitmapFont.TEXT_SET10, 20, 0, 0); + font2 = game.add.bitmapFont(game.world.centerX, 300, 'bluePink', 32, 32, Phaser.BitmapFont.TEXT_SET2, 10); + font2.setText("phaser is\nrocking :)", true, 0, 8, Phaser.BitmapFont.ALIGN_CENTER); + font2.anchor.set(0.5); - font.text = "using bitmap fonts rocks"; - - game.world.add(font); - - // font = new FlxBitmapFont(AssetsRegistry.goldFontPNG, 16, 16, "! :() ,?." + FlxBitmapFont.TEXT_SET10, 20, 0, 0); - // font.setText("using bitmap fonts\nin flixel is", true, 0, 8, FlxBitmapFont.ALIGN_CENTER, false); - - - // game.input.onDown.add(change, this); + game.input.onDown.add(change, this); } function change() { - // text.align = 'center'; - // text2.tint = Math.random() * 0xFFFFFF; + font2.tint = Math.random() * 0xFFFFFF; } function update() { - // text.text = 'Phaser & Pixi\nrocking!\n' + Math.round(game.time.now); + font2.rotation += 0.03; } diff --git a/src/gameobjects/BitmapFont.js b/src/gameobjects/BitmapFont.js index 5ea05215..99a58db4 100644 --- a/src/gameobjects/BitmapFont.js +++ b/src/gameobjects/BitmapFont.js @@ -18,7 +18,7 @@ * @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. * @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. */ -Phaser.BitmapFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { +Phaser.BitmapFont = function (game, x, y, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { /** * @property {number} characterWidth - The width of each character in the font set. @@ -137,7 +137,7 @@ Phaser.BitmapFont = function (game, key, characterWidth, characterHeight, chars, */ this.bmd = new Phaser.BitmapData(game, this.characterWidth, this.characterHeight); - Phaser.Image.call(this, game, 0, 0, this.bmd); + Phaser.Image.call(this, game, x, y, this.bmd); /** * @property {number} type - Base Phaser object type. @@ -277,7 +277,7 @@ Phaser.BitmapFont.prototype.setFixedWidth = function (width, lineAlignment) { * @param {string} [lineAlignment='left'] - Align each line of multi-line text. Set to BitmapFont.ALIGN_LEFT, BitmapFont.ALIGN_RIGHT or BitmapFont.ALIGN_CENTER. * @param {boolean} [allowLowerCase=false] - Lots of bitmap font sets only include upper-case characters, if yours needs to support lower case then set this to true. */ -Phaser.BitmapFont.prototype.setFixedWidth = function (content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase) { +Phaser.BitmapFont.prototype.setText = function (content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase) { this.multiLine = multiLine || false; this.customSpacingX = characterSpacing || 0; diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index 9165bd58..77c8a630 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -258,12 +258,37 @@ Phaser.GameObjectFactory.prototype = { }, /** - * * Create a new BitmapText object. + * Create a new BitmapFont object. + * + * @param {number} x - X position of the new bitmapText object. + * @param {number} y - Y position of the new bitmapText object. + * @param {string} font - The key of the BitmapFont as stored in Game.Cache. + * @param {number} characterWidth - The width of each character in the font set. + * @param {number} characterHeight - The height of each character in the font set. + * @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. + * @param {number} charsPerRow - The number of characters per row in the font set. + * @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here. + * @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here. + * @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. + * @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. + * @return {Phaser.BitmapFont} The newly created BitmapFont object. + */ + bitmapFont: function (x, y, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset, group) { + + if (typeof group === 'undefined') { group = this.world; } + + return group.add(new Phaser.BitmapFont(this.game, x, y, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)); + + }, + + /** + * Create a new BitmapText object. * * @method Phaser.GameObjectFactory#bitmapText * @param {number} x - X position of the new bitmapText object. * @param {number} y - Y position of the new bitmapText object. - * @param {string} font - The key of the BitmapFont as stored in Game.Cache. + * @param {string} font - The key of the BitmapText font as stored in Game.Cache. * @param {string} [text] - The actual text that will be rendered. Can be set later via BitmapText.text. * @param {number} [size] - The size the font will be rendered in, in pixels. * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. @@ -273,7 +298,7 @@ Phaser.GameObjectFactory.prototype = { if (typeof group === 'undefined') { group = this.world; } - return this.world.add(new Phaser.BitmapText(this.game, x, y, font, text, size)); + return group.add(new Phaser.BitmapText(this.game, x, y, font, text, size)); },