Skip to content

Commit 15b83e1

Browse files
committed
Added the new BitmapFont class. This is for rendering retro style fixed-width bitmap fonts into an Image object.
1 parent b38b00c commit 15b83e1

9 files changed

Lines changed: 597 additions & 10 deletions

File tree

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = function (grunt) {
9696
'src/gameobjects/Graphics.js',
9797
'src/gameobjects/RenderTexture.js',
9898
'src/gameobjects/SpriteBatch.js',
99+
'src/gameobjects/BitmapFont.js',
99100

100101
'src/system/Canvas.js',
101102
'src/system/StageScaleMode.js',

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ New features:
109109
* BitmapText now uses the new XML parser which should work under CocoonJS without clashes.
110110
* BitmapText signature changed so you can support fonts with spaces in their names.
111111
* 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.
112+
* Added the new BitmapFont class. This is for rendering retro style fixed-width bitmap fonts into an Image object.
112113

113114

114115
Updates:

build/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<script src="$path/src/gameobjects/Graphics.js"></script>
143143
<script src="$path/src/gameobjects/RenderTexture.js"></script>
144144
<script src="$path/src/gameobjects/SpriteBatch.js"></script>
145+
<script src="$path/src/gameobjects/BitmapFont.js"></script>
145146
146147
<script src="$path/src/system/Canvas.js"></script>
147148
<script src="$path/src/system/StageScaleMode.js"></script>

examples/wip/bitmaptext1.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function create() {
2424
function change() {
2525

2626
text.align = 'center';
27-
2827
text2.tint = Math.random() * 0xFFFFFF;
2928

3029
}

examples/wip/bitmaptext2.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
3+
4+
function preload() {
5+
6+
game.load.image('font', 'assets/fonts/gold_font.png');
7+
8+
}
9+
10+
var font;
11+
12+
function create() {
13+
14+
// text = game.add.bitmapText(100, 100, 'carrier', 'Phaser and Pixi\nrocking!', 32);
15+
16+
font = new Phaser.BitmapFont(game, 'font', 16, 16, "! :() ,?." + Phaser.BitmapFont.TEXT_SET10, 20, 0, 0);
17+
18+
font.text = "using bitmap fonts rocks";
19+
20+
game.world.add(font);
21+
22+
// font = new FlxBitmapFont(AssetsRegistry.goldFontPNG, 16, 16, "! :() ,?." + FlxBitmapFont.TEXT_SET10, 20, 0, 0);
23+
// font.setText("using bitmap fonts\nin flixel is", true, 0, 8, FlxBitmapFont.ALIGN_CENTER, false);
24+
25+
26+
// game.input.onDown.add(change, this);
27+
28+
}
29+
30+
function change() {
31+
32+
// text.align = 'center';
33+
// text2.tint = Math.random() * 0xFFFFFF;
34+
35+
}
36+
37+
function update() {
38+
39+
// text.text = 'Phaser & Pixi\nrocking!\n' + Math.round(game.time.now);
40+
41+
}

src/Phaser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ var Phaser = Phaser || {
3535
CANVAS_FILTER: 14,
3636
WEBGL_FILTER: 15,
3737
ELLIPSE: 16,
38-
SPRITEBATCH: 16,
38+
SPRITEBATCH: 17,
39+
BITMAPFONT: 18,
3940

4041
NONE: 0,
4142
LEFT: 1,

src/gameobjects/BitmapData.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ Phaser.BitmapData.prototype = {
144144

145145
},
146146

147+
/**
148+
* Resizes the BitmapData.
149+
* @method Phaser.BitmapData#resize
150+
*/
151+
resize: function (width, height) {
152+
153+
if (width !== this.width || height !== this.height)
154+
{
155+
this.width = width;
156+
this.height = height;
157+
this.canvas.width = width;
158+
this.canvas.height = height;
159+
this.textureFrame.width = width;
160+
this.textureFrame.height = height;
161+
this.imageData = this.context.getImageData(0, 0, width, height);
162+
}
163+
164+
this._dirty = true;
165+
166+
},
167+
147168
refreshBuffer: function () {
148169

149170
this.imageData = this.context.getImageData(0, 0, this.width, this.height);
@@ -246,6 +267,12 @@ Phaser.BitmapData.prototype = {
246267

247268
},
248269

270+
copyPixels: function (source, area, destX, destY) {
271+
272+
this.context.drawImage(source, area.x, area.y, area.width, area.height, destX, destY, area.width, area.height);
273+
274+
},
275+
249276
/**
250277
* If the game is running in WebGL this will push the texture up to the GPU if it's dirty.
251278
* This is called automatically if the BitmapData is being used by a Sprite, otherwise you need to remember to call it in your render function.

0 commit comments

Comments
 (0)