diff --git a/Gruntfile.js b/Gruntfile.js index 49b4c4b5..0ca79839 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -145,7 +145,7 @@ module.exports = function (grunt) { 'src/gameobjects/Graphics.js', 'src/gameobjects/RenderTexture.js', 'src/gameobjects/SpriteBatch.js', - 'src/gameobjects/BitmapFont.js', + 'src/gameobjects/RetroFont.js', 'src/system/Canvas.js', 'src/system/Device.js', diff --git a/README.md b/README.md index 2993c770..9bf44c01 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ New features: * BitmapText now uses the new XML parser which should work under CocoonJS without clashes. * BitmapText signature changed so you can support fonts with spaces in their names. * Loader.bitmapFont now has 2 extra parameters: xSpacing and ySpacing. These allow you to add extra spacing to each letter or line of the font. -* Added the new BitmapFont class. This is for rendering retro style fixed-width bitmap fonts into an Image object. It's a texture you can apply to a Sprite/Image. +* Added the new RetroFont class. This is for rendering fixed-width bitmap fonts into an Image object. It's a texture you can apply to a Sprite/Image. * Added Cache.updateFrameData which is really useful for swapping FrameData blocks in the cache. * Loader.physics now lets you load Lime + Corona JSON Physics data, which can be used with Body.loadPolygon and Body.loadData. * Cache.addPhysicsData and Cache.getPhysicsData allow you to store parsed JSON physics data in the cache, for sharing between Bodies. diff --git a/build/config.php b/build/config.php index 48a11c59..aa105f96 100644 --- a/build/config.php +++ b/build/config.php @@ -100,7 +100,7 @@ - + diff --git a/examples/_site/view_full.html b/examples/_site/view_full.html index 6e593edd..e1e83f85 100644 --- a/examples/_site/view_full.html +++ b/examples/_site/view_full.html @@ -106,7 +106,7 @@ - + diff --git a/examples/_site/view_lite.html b/examples/_site/view_lite.html index 1e9f01c7..ed6e9f40 100644 --- a/examples/_site/view_lite.html +++ b/examples/_site/view_lite.html @@ -106,7 +106,7 @@ - + diff --git a/examples/assets/fonts/1984-nocooper-tebirod_logo.png b/examples/assets/fonts/1984-nocooper-tebirod_logo.png deleted file mode 100644 index d01a7851..00000000 Binary files a/examples/assets/fonts/1984-nocooper-tebirod_logo.png and /dev/null differ diff --git a/examples/assets/fonts/carrier_command.png b/examples/assets/fonts/bitmapFonts/carrier_command.png similarity index 100% rename from examples/assets/fonts/carrier_command.png rename to examples/assets/fonts/bitmapFonts/carrier_command.png diff --git a/examples/assets/fonts/carrier_command.xml b/examples/assets/fonts/bitmapFonts/carrier_command.xml similarity index 100% rename from examples/assets/fonts/carrier_command.xml rename to examples/assets/fonts/bitmapFonts/carrier_command.xml diff --git a/examples/assets/fonts/desyrel-pink.png b/examples/assets/fonts/bitmapFonts/desyrel-pink.png similarity index 100% rename from examples/assets/fonts/desyrel-pink.png rename to examples/assets/fonts/bitmapFonts/desyrel-pink.png diff --git a/examples/assets/fonts/desyrel-pink.xml b/examples/assets/fonts/bitmapFonts/desyrel-pink.xml similarity index 100% rename from examples/assets/fonts/desyrel-pink.xml rename to examples/assets/fonts/bitmapFonts/desyrel-pink.xml diff --git a/examples/assets/fonts/desyrel.png b/examples/assets/fonts/bitmapFonts/desyrel.png similarity index 100% rename from examples/assets/fonts/desyrel.png rename to examples/assets/fonts/bitmapFonts/desyrel.png diff --git a/examples/assets/fonts/desyrel.xml b/examples/assets/fonts/bitmapFonts/desyrel.xml similarity index 100% rename from examples/assets/fonts/desyrel.xml rename to examples/assets/fonts/bitmapFonts/desyrel.xml diff --git a/examples/assets/fonts/bitmapFonts/shortStack.fnt b/examples/assets/fonts/bitmapFonts/shortStack.fnt new file mode 100644 index 00000000..95fde080 --- /dev/null +++ b/examples/assets/fonts/bitmapFonts/shortStack.fnt @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/assets/fonts/bitmapFonts/shortStack.png b/examples/assets/fonts/bitmapFonts/shortStack.png new file mode 100644 index 00000000..9ac1b740 Binary files /dev/null and b/examples/assets/fonts/bitmapFonts/shortStack.png differ diff --git a/examples/assets/fonts/032.png b/examples/assets/fonts/retroFonts/032.png similarity index 100% rename from examples/assets/fonts/032.png rename to examples/assets/fonts/retroFonts/032.png diff --git a/examples/assets/fonts/036.png b/examples/assets/fonts/retroFonts/036.png similarity index 100% rename from examples/assets/fonts/036.png rename to examples/assets/fonts/retroFonts/036.png diff --git a/examples/assets/fonts/047.png b/examples/assets/fonts/retroFonts/047.png similarity index 100% rename from examples/assets/fonts/047.png rename to examples/assets/fonts/retroFonts/047.png diff --git a/examples/assets/fonts/070.png b/examples/assets/fonts/retroFonts/070.png similarity index 100% rename from examples/assets/fonts/070.png rename to examples/assets/fonts/retroFonts/070.png diff --git a/examples/assets/fonts/072.png b/examples/assets/fonts/retroFonts/072.png similarity index 100% rename from examples/assets/fonts/072.png rename to examples/assets/fonts/retroFonts/072.png diff --git a/examples/assets/fonts/087.png b/examples/assets/fonts/retroFonts/087.png similarity index 100% rename from examples/assets/fonts/087.png rename to examples/assets/fonts/retroFonts/087.png diff --git a/examples/assets/fonts/110.png b/examples/assets/fonts/retroFonts/110.png similarity index 100% rename from examples/assets/fonts/110.png rename to examples/assets/fonts/retroFonts/110.png diff --git a/examples/assets/fonts/141.png b/examples/assets/fonts/retroFonts/141.png similarity index 100% rename from examples/assets/fonts/141.png rename to examples/assets/fonts/retroFonts/141.png diff --git a/examples/assets/fonts/165.png b/examples/assets/fonts/retroFonts/165.png similarity index 100% rename from examples/assets/fonts/165.png rename to examples/assets/fonts/retroFonts/165.png diff --git a/examples/assets/fonts/16x16-blue-metal.png b/examples/assets/fonts/retroFonts/16x16-blue-metal.png similarity index 100% rename from examples/assets/fonts/16x16-blue-metal.png rename to examples/assets/fonts/retroFonts/16x16-blue-metal.png diff --git a/examples/assets/fonts/16x16-cool-metal.png b/examples/assets/fonts/retroFonts/16x16-cool-metal.png similarity index 100% rename from examples/assets/fonts/16x16-cool-metal.png rename to examples/assets/fonts/retroFonts/16x16-cool-metal.png diff --git a/examples/assets/fonts/171.png b/examples/assets/fonts/retroFonts/171.png similarity index 100% rename from examples/assets/fonts/171.png rename to examples/assets/fonts/retroFonts/171.png diff --git a/examples/assets/fonts/225.png b/examples/assets/fonts/retroFonts/225.png similarity index 100% rename from examples/assets/fonts/225.png rename to examples/assets/fonts/retroFonts/225.png diff --git a/examples/assets/fonts/231.png b/examples/assets/fonts/retroFonts/231.png similarity index 100% rename from examples/assets/fonts/231.png rename to examples/assets/fonts/retroFonts/231.png diff --git a/examples/assets/fonts/260.png b/examples/assets/fonts/retroFonts/260.png similarity index 100% rename from examples/assets/fonts/260.png rename to examples/assets/fonts/retroFonts/260.png diff --git a/examples/assets/fonts/283.png b/examples/assets/fonts/retroFonts/283.png similarity index 100% rename from examples/assets/fonts/283.png rename to examples/assets/fonts/retroFonts/283.png diff --git a/examples/assets/fonts/284.png b/examples/assets/fonts/retroFonts/284.png similarity index 100% rename from examples/assets/fonts/284.png rename to examples/assets/fonts/retroFonts/284.png diff --git a/examples/assets/fonts/297.png b/examples/assets/fonts/retroFonts/297.png similarity index 100% rename from examples/assets/fonts/297.png rename to examples/assets/fonts/retroFonts/297.png diff --git a/examples/assets/fonts/313.png b/examples/assets/fonts/retroFonts/313.png similarity index 100% rename from examples/assets/fonts/313.png rename to examples/assets/fonts/retroFonts/313.png diff --git a/examples/assets/fonts/8x9_golden.png b/examples/assets/fonts/retroFonts/8x9_golden.png similarity index 100% rename from examples/assets/fonts/8x9_golden.png rename to examples/assets/fonts/retroFonts/8x9_golden.png diff --git a/examples/assets/fonts/ACFRESET.png b/examples/assets/fonts/retroFonts/ACFRESET.png similarity index 100% rename from examples/assets/fonts/ACFRESET.png rename to examples/assets/fonts/retroFonts/ACFRESET.png diff --git a/examples/assets/fonts/FONT3.png b/examples/assets/fonts/retroFonts/FONT3.png similarity index 100% rename from examples/assets/fonts/FONT3.png rename to examples/assets/fonts/retroFonts/FONT3.png diff --git a/examples/assets/fonts/KNIGHT3.png b/examples/assets/fonts/retroFonts/KNIGHT3.png similarity index 100% rename from examples/assets/fonts/KNIGHT3.png rename to examples/assets/fonts/retroFonts/KNIGHT3.png diff --git a/examples/assets/fonts/MEGADETH.GIF b/examples/assets/fonts/retroFonts/MEGADETH.GIF similarity index 100% rename from examples/assets/fonts/MEGADETH.GIF rename to examples/assets/fonts/retroFonts/MEGADETH.GIF diff --git a/examples/assets/fonts/MEGAMINI.GIF b/examples/assets/fonts/retroFonts/MEGAMINI.GIF similarity index 100% rename from examples/assets/fonts/MEGAMINI.GIF rename to examples/assets/fonts/retroFonts/MEGAMINI.GIF diff --git a/examples/assets/fonts/PICKPILE.png b/examples/assets/fonts/retroFonts/PICKPILE.png similarity index 100% rename from examples/assets/fonts/PICKPILE.png rename to examples/assets/fonts/retroFonts/PICKPILE.png diff --git a/examples/assets/fonts/STEEL.png b/examples/assets/fonts/retroFonts/STEEL.png similarity index 100% rename from examples/assets/fonts/STEEL.png rename to examples/assets/fonts/retroFonts/STEEL.png diff --git a/examples/assets/fonts/ST_ADM.GIF b/examples/assets/fonts/retroFonts/ST_ADM.GIF similarity index 100% rename from examples/assets/fonts/ST_ADM.GIF rename to examples/assets/fonts/retroFonts/ST_ADM.GIF diff --git a/examples/assets/fonts/WAYNE_3D.png b/examples/assets/fonts/retroFonts/WAYNE_3D.png similarity index 100% rename from examples/assets/fonts/WAYNE_3D.png rename to examples/assets/fonts/retroFonts/WAYNE_3D.png diff --git a/examples/assets/fonts/bluepink_font.png b/examples/assets/fonts/retroFonts/bluepink_font.png similarity index 100% rename from examples/assets/fonts/bluepink_font.png rename to examples/assets/fonts/retroFonts/bluepink_font.png diff --git a/examples/assets/fonts/bubbles_font.png b/examples/assets/fonts/retroFonts/bubbles_font.png similarity index 100% rename from examples/assets/fonts/bubbles_font.png rename to examples/assets/fonts/retroFonts/bubbles_font.png diff --git a/examples/assets/fonts/deltaforce_font.png b/examples/assets/fonts/retroFonts/deltaforce_font.png similarity index 100% rename from examples/assets/fonts/deltaforce_font.png rename to examples/assets/fonts/retroFonts/deltaforce_font.png diff --git a/examples/assets/fonts/digits_font_ilkke.png b/examples/assets/fonts/retroFonts/digits_font_ilkke.png similarity index 100% rename from examples/assets/fonts/digits_font_ilkke.png rename to examples/assets/fonts/retroFonts/digits_font_ilkke.png diff --git a/examples/assets/fonts/gold_font.png b/examples/assets/fonts/retroFonts/gold_font.png similarity index 100% rename from examples/assets/fonts/gold_font.png rename to examples/assets/fonts/retroFonts/gold_font.png diff --git a/examples/assets/fonts/grid_legend_font_aliased.png b/examples/assets/fonts/retroFonts/grid_legend_font_aliased.png similarity index 100% rename from examples/assets/fonts/grid_legend_font_aliased.png rename to examples/assets/fonts/retroFonts/grid_legend_font_aliased.png diff --git a/examples/assets/fonts/grid_legend_font_solid.png b/examples/assets/fonts/retroFonts/grid_legend_font_solid.png similarity index 100% rename from examples/assets/fonts/grid_legend_font_solid.png rename to examples/assets/fonts/retroFonts/grid_legend_font_solid.png diff --git a/examples/assets/fonts/interference_48x48.png b/examples/assets/fonts/retroFonts/interference_48x48.png similarity index 100% rename from examples/assets/fonts/interference_48x48.png rename to examples/assets/fonts/retroFonts/interference_48x48.png diff --git a/examples/assets/fonts/interference_48x48_negiert.png b/examples/assets/fonts/retroFonts/interference_48x48_negiert.png similarity index 100% rename from examples/assets/fonts/interference_48x48_negiert.png rename to examples/assets/fonts/retroFonts/interference_48x48_negiert.png diff --git a/examples/assets/fonts/knighthawks_font.png b/examples/assets/fonts/retroFonts/knighthawks_font.png similarity index 100% rename from examples/assets/fonts/knighthawks_font.png rename to examples/assets/fonts/retroFonts/knighthawks_font.png diff --git a/examples/assets/fonts/megadeth_tlb.png b/examples/assets/fonts/retroFonts/megadeth_tlb.png similarity index 100% rename from examples/assets/fonts/megadeth_tlb.png rename to examples/assets/fonts/retroFonts/megadeth_tlb.png diff --git a/examples/assets/fonts/naos_font.png b/examples/assets/fonts/retroFonts/naos_font.png similarity index 100% rename from examples/assets/fonts/naos_font.png rename to examples/assets/fonts/retroFonts/naos_font.png diff --git a/examples/assets/fonts/robocop_font.png b/examples/assets/fonts/retroFonts/robocop_font.png similarity index 100% rename from examples/assets/fonts/robocop_font.png rename to examples/assets/fonts/retroFonts/robocop_font.png diff --git a/examples/assets/fonts/spaz_font.png b/examples/assets/fonts/retroFonts/spaz_font.png similarity index 100% rename from examples/assets/fonts/spaz_font.png rename to examples/assets/fonts/retroFonts/spaz_font.png diff --git a/examples/assets/fonts/steelpp_font.png b/examples/assets/fonts/retroFonts/steelpp_font.png similarity index 100% rename from examples/assets/fonts/steelpp_font.png rename to examples/assets/fonts/retroFonts/steelpp_font.png diff --git a/examples/assets/fonts/tbj_font.png b/examples/assets/fonts/retroFonts/tbj_font.png similarity index 100% rename from examples/assets/fonts/tbj_font.png rename to examples/assets/fonts/retroFonts/tbj_font.png diff --git a/examples/assets/fonts/tiw_font.png b/examples/assets/fonts/retroFonts/tiw_font.png similarity index 100% rename from examples/assets/fonts/tiw_font.png rename to examples/assets/fonts/retroFonts/tiw_font.png diff --git a/examples/assets/fonts/tsk_font.png b/examples/assets/fonts/retroFonts/tsk_font.png similarity index 100% rename from examples/assets/fonts/tsk_font.png rename to examples/assets/fonts/retroFonts/tsk_font.png diff --git a/examples/assets/fonts/textDemoBG.jpg b/examples/assets/fonts/textDemoBG.jpg deleted file mode 100644 index 5955e59f..00000000 Binary files a/examples/assets/fonts/textDemoBG.jpg and /dev/null differ diff --git a/examples/text/bitmap fonts.js b/examples/text/bitmap fonts.js index 5cf0d9c2..267f2620 100644 --- a/examples/text/bitmap fonts.js +++ b/examples/text/bitmap fonts.js @@ -3,7 +3,7 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p function preload() { - game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml'); + game.load.bitmapFont('desyrel', 'assets/fonts/bitmapFonts/desyrel.png', 'assets/fonts/bitmapFonts/desyrel.xml'); } diff --git a/examples/text/hello arial.js b/examples/text/hello arial.js index df40c8cb..f1e7dd15 100644 --- a/examples/text/hello arial.js +++ b/examples/text/hello arial.js @@ -2,11 +2,9 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: function create() { - var text = "- phaser -\nwith a sprinkle of\npixi dust"; - var style = { font: "65px Arial", fill: "#ff0044", align: "center" }; + var style = { font: "65px Arial", fill: "#ff0044", align: "center" }; + var text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nwith a sprinkle of\npixi dust", style); - var t = game.add.text(game.world.centerX, game.world.centerY, text, style); - - t.anchor.setTo(0.5, 0.5); + text.anchor.set(0.5); } \ No newline at end of file diff --git a/examples/wip/bitmaptext littera.js b/examples/wip/bitmaptext littera.js new file mode 100644 index 00000000..89211930 --- /dev/null +++ b/examples/wip/bitmaptext littera.js @@ -0,0 +1,20 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.bitmapFont('shortStack', 'assets/fonts/bitmapFonts/shortStack.png', 'assets/fonts/bitmapFonts/shortStack.fnt'); + +} + +var text; + +function create() { + + text = game.add.bitmapText(100, 100, 'shortStack', 'Bitmap Fonts\nfrom Littera', 64); + +} + +function update() { + +} diff --git a/examples/wip/bitmaptext1.js b/examples/wip/bitmaptext1.js index 9589d16e..a5ab9781 100644 --- a/examples/wip/bitmaptext1.js +++ b/examples/wip/bitmaptext1.js @@ -3,8 +3,8 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p function preload() { - game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml', null, 0, -32); - game.load.bitmapFont('carrier', 'assets/fonts/carrier_command.png', 'assets/fonts/carrier_command.xml', null, 0, 24); + game.load.bitmapFont('desyrel', 'assets/fonts/bitmapFonts/desyrel.png', 'assets/fonts/desyrel.xml', null, 0, -32); + game.load.bitmapFont('carrier', 'assets/fonts/bitmapFonts/carrier_command.png', 'assets/fonts/carrier_command.xml', null, 0, 24); } diff --git a/examples/wip/bitmaptext2.js b/examples/wip/bitmaptext2.js index 56c01508..718d75ba 100644 --- a/examples/wip/bitmaptext2.js +++ b/examples/wip/bitmaptext2.js @@ -3,8 +3,8 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p function preload() { - game.load.image('goldFont', 'assets/fonts/gold_font.png'); - game.load.image('bluePink', 'assets/fonts/bluepink_font.png'); + game.load.image('goldFont', 'assets/fonts/retroFonts/gold_font.png'); + game.load.image('bluePink', 'assets/fonts/retroFonts/bluepink_font.png'); } diff --git a/examples/wip/bitmaptext3.js b/examples/wip/bitmaptext3.js index 1d861f06..19e0cf36 100644 --- a/examples/wip/bitmaptext3.js +++ b/examples/wip/bitmaptext3.js @@ -4,7 +4,7 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p function preload() { - game.load.image('knightHawks', 'assets/fonts/KNIGHT3.png'); + game.load.image('knightHawks', 'assets/fonts/retroFonts/KNIGHT3.png'); } diff --git a/src/gameobjects/GameObjectCreator.js b/src/gameobjects/GameObjectCreator.js index 6ccf67fc..b6969b4d 100644 --- a/src/gameobjects/GameObjectCreator.js +++ b/src/gameobjects/GameObjectCreator.js @@ -230,12 +230,15 @@ Phaser.GameObjectCreator.prototype = { }, /** - * Create a new BitmapFont object to be used as a texture for an Image or Sprite and optionally add it to the Cache. - * The texture can be asssigned or one or multiple images/sprites, but note that the text the BitmapFont uses will be shared across them all, - * i.e. if you need each Image to have different text in it, then you need to create multiple BitmapFont objects. + * Create a new RetroFont object to be used as a texture for an Image or Sprite and optionally add it to the Cache. + * A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set. + * If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText + * is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text. + * The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all, + * i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects. * - * @method Phaser.GameObjectCreator#bitmapFont - * @param {string} font - The key of the image in the Game.Cache that the BitmapFont will use. + * @method Phaser.GameObjectCreator#retroFont + * @param {string} font - The key of the image in the Game.Cache that the RetroFont will use. * @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. @@ -244,11 +247,11 @@ Phaser.GameObjectCreator.prototype = { * @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. - * @return {Phaser.BitmapFont} The newly created BitmapFont texture which can be applied to an Image or Sprite. + * @return {Phaser.RetroFont} The newly created RetroFont texture which can be applied to an Image or Sprite. */ - bitmapFont: function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { + retroFont: function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { - return new Phaser.BitmapFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset); + return new Phaser.RetroFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset); }, diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index a29fb6d7..5a9002bd 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -258,12 +258,15 @@ Phaser.GameObjectFactory.prototype = { }, /** - * Create a new BitmapFont object to be used as a texture for an Image or Sprite and optionally add it to the Cache. - * The texture can be asssigned or one or multiple images/sprites, but note that the text the BitmapFont uses will be shared across them all, - * i.e. if you need each Image to have different text in it, then you need to create multiple BitmapFont objects. + * Create a new RetroFont object to be used as a texture for an Image or Sprite and optionally add it to the Cache. + * A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set. + * If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText + * is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text. + * The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all, + * i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects. * - * @method Phaser.GameObjectFactory#bitmapFont - * @param {string} font - The key of the image in the Game.Cache that the BitmapFont will use. + * @method Phaser.GameObjectFactory#retroFont + * @param {string} font - The key of the image in the Game.Cache that the RetroFont will use. * @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. @@ -272,11 +275,11 @@ Phaser.GameObjectFactory.prototype = { * @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. - * @return {Phaser.BitmapFont} The newly created BitmapFont texture which can be applied to an Image or Sprite. + * @return {Phaser.RetroFont} The newly created RetroFont texture which can be applied to an Image or Sprite. */ - bitmapFont: function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { + retroFont: function (font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { - return new Phaser.BitmapFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset); + return new Phaser.RetroFont(this.game, font, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset); }, diff --git a/src/gameobjects/BitmapFont.js b/src/gameobjects/RetroFont.js similarity index 81% rename from src/gameobjects/BitmapFont.js rename to src/gameobjects/RetroFont.js index 663b22f5..c84d6228 100644 --- a/src/gameobjects/BitmapFont.js +++ b/src/gameobjects/RetroFont.js @@ -5,7 +5,7 @@ */ /** -* @class Phaser.BitmapFont +* @class Phaser.RetroFont * @extends Phaser.RenderTexture * @constructor * @param {Phaser.Game} game - Current game instance. @@ -19,7 +19,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.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) { /** * @property {number} characterWidth - The width of each character in the font set. @@ -57,7 +57,7 @@ Phaser.BitmapFont = function (game, key, characterWidth, characterHeight, chars, this.offsetY = yOffset || 0; /** - * @property {string} align - Alignment of the text when multiLine = true or a fixedWidth is set. Set to BitmapFont.ALIGN_LEFT (default), BitmapFont.ALIGN_RIGHT or BitmapFont.ALIGN_CENTER. + * @property {string} align - Alignment of the text when multiLine = true or a fixedWidth is set. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. */ this.align = "left"; @@ -86,7 +86,7 @@ Phaser.BitmapFont = function (game, key, characterWidth, characterHeight, chars, this.customSpacingY = 0; /** - * If you need this BitmapFont image to have a fixed width you can set the width in this value. + * If you need this RetroFont image to have a fixed width you can set the width in this value. * If text is wider than the width specified it will be cropped off. * @property {number} fixedWidth */ @@ -157,117 +157,117 @@ Phaser.BitmapFont = function (game, key, characterWidth, characterHeight, chars, }; -Phaser.BitmapFont.prototype = Object.create(Phaser.RenderTexture.prototype); -Phaser.BitmapFont.prototype.constructor = Phaser.BitmapFont; +Phaser.RetroFont.prototype = Object.create(Phaser.RenderTexture.prototype); +Phaser.RetroFont.prototype.constructor = Phaser.RetroFont; /** * Align each line of multi-line text to the left. * @constant * @type {string} */ -Phaser.BitmapFont.ALIGN_LEFT = "left"; +Phaser.RetroFont.ALIGN_LEFT = "left"; /** * Align each line of multi-line text to the right. * @constant * @type {string} */ -Phaser.BitmapFont.ALIGN_RIGHT = "right"; +Phaser.RetroFont.ALIGN_RIGHT = "right"; /** * Align each line of multi-line text in the center. * @constant * @type {string} */ -Phaser.BitmapFont.ALIGN_CENTER = "center"; +Phaser.RetroFont.ALIGN_CENTER = "center"; /** * Text Set 1 = !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET1 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; +Phaser.RetroFont.TEXT_SET1 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; /** * Text Set 2 = !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET2 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +Phaser.RetroFont.TEXT_SET2 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** * Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "; +Phaser.RetroFont.TEXT_SET3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "; /** * Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"; +Phaser.RetroFont.TEXT_SET4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"; /** * Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789 * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789"; +Phaser.RetroFont.TEXT_SET5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789"; /** * Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET6 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' "; +Phaser.RetroFont.TEXT_SET6 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' "; /** * Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39 * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET7 = "AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39"; +Phaser.RetroFont.TEXT_SET7 = "AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39"; /** * Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET8 = "0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +Phaser.RetroFont.TEXT_SET8 = "0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** * Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?! * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!"; +Phaser.RetroFont.TEXT_SET9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!"; /** * Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET10 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +Phaser.RetroFont.TEXT_SET10 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** * Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789 * @constant * @type {string} */ -Phaser.BitmapFont.TEXT_SET11 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789"; +Phaser.RetroFont.TEXT_SET11 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789"; /** * If you need this FlxSprite to have a fixed width and custom alignment you can set the width here.
* If text is wider than the width specified it will be cropped off. * -* @method Phaser.BitmapFont#setFixedWidth -* @memberof Phaser.BitmapFont -* @param {number} width - Width in pixels of this BitmapFont. Set to zero to disable and re-enable automatic resizing. -* @param {string} [lineAlignment='left'] - Align the text within this width. Set to BitmapFont.ALIGN_LEFT (default), BitmapFont.ALIGN_RIGHT or BitmapFont.ALIGN_CENTER. +* @method Phaser.RetroFont#setFixedWidth +* @memberof Phaser.RetroFont +* @param {number} width - Width in pixels of this RetroFont. Set to zero to disable and re-enable automatic resizing. +* @param {string} [lineAlignment='left'] - Align the text within this width. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. */ -Phaser.BitmapFont.prototype.setFixedWidth = function (width, lineAlignment) { +Phaser.RetroFont.prototype.setFixedWidth = function (width, lineAlignment) { if (typeof lineAlignment === 'undefined') { lineAlignment = 'left'; } @@ -279,16 +279,16 @@ Phaser.BitmapFont.prototype.setFixedWidth = function (width, lineAlignment) { /** * A helper function that quickly sets lots of variables at once, and then updates the text. * -* @method Phaser.BitmapFont#setText -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#setText +* @memberof Phaser.RetroFont * @param {string} content - The text of this sprite. * @param {boolean} [multiLine=false] - Set to true if you want to support carriage-returns in the text and create a multi-line sprite instead of a single line. * @param {number} [characterSpacing=0] - To add horizontal spacing between each character specify the amount in pixels. * @param {number} [lineSpacing=0] - To add vertical spacing between each line of text, set the amount in pixels. -* @param {string} [lineAlignment='left'] - Align each line of multi-line text. Set to BitmapFont.ALIGN_LEFT, BitmapFont.ALIGN_RIGHT or BitmapFont.ALIGN_CENTER. +* @param {string} [lineAlignment='left'] - Align each line of multi-line text. Set to RetroFont.ALIGN_LEFT, RetroFont.ALIGN_RIGHT or RetroFont.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.setText = function (content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase) { +Phaser.RetroFont.prototype.setText = function (content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase) { this.multiLine = multiLine || false; this.customSpacingX = characterSpacing || 0; @@ -314,10 +314,10 @@ Phaser.BitmapFont.prototype.setText = function (content, multiLine, characterSpa /** * Over rides the default PIXI.RenderTexture resize event as we need our baseTexture resized as well. * -* @method Phaser.BitmapFont#resize -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#resize +* @memberof Phaser.RetroFont */ -Phaser.BitmapFont.prototype.resize = function (width, height) { +Phaser.RetroFont.prototype.resize = function (width, height) { this.width = width; this.height = height; @@ -349,10 +349,10 @@ Phaser.BitmapFont.prototype.resize = function (width, height) { /** * Updates the BitmapData of the Sprite with the text * -* @method Phaser.BitmapFont#buildBitmapFontText -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#buildRetroFontText +* @memberof Phaser.RetroFont */ -Phaser.BitmapFont.prototype.buildBitmapFontText = function () { +Phaser.RetroFont.prototype.buildRetroFontText = function () { var cx = 0; var cy = 0; @@ -378,15 +378,15 @@ Phaser.BitmapFont.prototype.buildBitmapFontText = function () { // This line of text is held in lines[i] - need to work out the alignment switch (this.align) { - case Phaser.BitmapFont.ALIGN_LEFT: + case Phaser.RetroFont.ALIGN_LEFT: cx = 0; break; - case Phaser.BitmapFont.ALIGN_RIGHT: + case Phaser.RetroFont.ALIGN_RIGHT: cx = this.width - (lines[i].length * (this.characterWidth + this.customSpacingX)); break; - case Phaser.BitmapFont.ALIGN_CENTER: + case Phaser.RetroFont.ALIGN_CENTER: cx = (this.width / 2) - ((lines[i].length * (this.characterWidth + this.customSpacingX)) / 2); cx += this.customSpacingX / 2; break; @@ -418,15 +418,15 @@ Phaser.BitmapFont.prototype.buildBitmapFontText = function () { switch (this.align) { - case Phaser.BitmapFont.ALIGN_LEFT: + case Phaser.RetroFont.ALIGN_LEFT: cx = 0; break; - case Phaser.BitmapFont.ALIGN_RIGHT: + case Phaser.RetroFont.ALIGN_RIGHT: cx = this.width - (this._text.length * (this.characterWidth + this.customSpacingX)); break; - case Phaser.BitmapFont.ALIGN_CENTER: + case Phaser.RetroFont.ALIGN_CENTER: cx = (this.width / 2) - ((this._text.length * (this.characterWidth + this.customSpacingX)) / 2); cx += this.customSpacingX / 2; break; @@ -441,14 +441,14 @@ Phaser.BitmapFont.prototype.buildBitmapFontText = function () { * Internal function that takes a single line of text (2nd parameter) and pastes it into the BitmapData at the given coordinates. * Used by getLine and getMultiLine * -* @method Phaser.BitmapFont#buildBitmapFontText -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#buildRetroFontText +* @memberof Phaser.RetroFont * @param {string} line - The single line of text to paste. * @param {number} x - The x coordinate. * @param {number} y - The y coordinate. * @param {number} customSpacingX - Custom X spacing. */ -Phaser.BitmapFont.prototype.pasteLine = function (line, x, y, customSpacingX) { +Phaser.RetroFont.prototype.pasteLine = function (line, x, y, customSpacingX) { var p = new Phaser.Point(); @@ -482,11 +482,11 @@ Phaser.BitmapFont.prototype.pasteLine = function (line, x, y, customSpacingX) { /** * Works out the longest line of text in _text and returns its length * -* @method Phaser.BitmapFont#getLongestLine -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#getLongestLine +* @memberof Phaser.RetroFont * @return {number} The length of the longest line of text. */ -Phaser.BitmapFont.prototype.getLongestLine = function () { +Phaser.RetroFont.prototype.getLongestLine = function () { var longestLine = 0; @@ -509,13 +509,13 @@ Phaser.BitmapFont.prototype.getLongestLine = function () { /** * Internal helper function that removes all unsupported characters from the _text String, leaving only characters contained in the font set. * -* @method Phaser.BitmapFont#removeUnsupportedCharacters -* @memberof Phaser.BitmapFont +* @method Phaser.RetroFont#removeUnsupportedCharacters +* @memberof Phaser.RetroFont * @protected * @param {boolean} [stripCR=true] - Should it strip carriage returns as well? * @return {string} A clean version of the string. */ -Phaser.BitmapFont.prototype.removeUnsupportedCharacters = function (stripCR) { +Phaser.RetroFont.prototype.removeUnsupportedCharacters = function (stripCR) { var newString = ""; @@ -537,7 +537,7 @@ Phaser.BitmapFont.prototype.removeUnsupportedCharacters = function (stripCR) { * @name Phaser.BitmapText#text * @property {string} text - Set this value to update the text in this sprite. Carriage returns are automatically stripped out if multiLine is false. Text is converted to upper case if autoUpperCase is true. */ -Object.defineProperty(Phaser.BitmapFont.prototype, "text", { +Object.defineProperty(Phaser.RetroFont.prototype, "text", { get: function () { @@ -564,7 +564,7 @@ Object.defineProperty(Phaser.BitmapFont.prototype, "text", { this.removeUnsupportedCharacters(this.multiLine); - this.buildBitmapFontText(); + this.buildRetroFontText(); } }