Skip to content

Commit bca64c2

Browse files
committed
Huge update to Phaser.Text. Much more lean, but loads of great new options added including drop shadows, gradient fills, fonts with spaces in the name, etc.
1 parent 4aa945f commit bca64c2

10 files changed

Lines changed: 654 additions & 142 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Significant API changes:
7272
* PixiPatch no longer needed, all features that it patched are now native in Pixi :)
7373
* Removed: Sprite.offset, center, topLeft, topRight, bottomRight, bottomLeft and bounds as no longer needed internally. Use Sprite.getBounds() to derive them.
7474
* Button now extends Phaser.Image not Phaser.Sprite, all the same functionality as before remains, just no animations or physics body.
75+
* Text.content has been replaced with Text.text.
7576

7677

7778
New features:
@@ -80,6 +81,10 @@ New features:
8081
* You can now use the hitArea property on Sprites and Image objects. hitArea can be a geometry object (Rectangle, Circle, Polygon, Ellipse) and is used in pointerOver checks.
8182
* InputManager.getLocalPosition(displayObject, pointer, output) will return the local coordinates of the specified displayObject and pointer.
8283
* InputManager.hitTest will test for pointer hits against a Sprite/Image, its hitArea (if set) or any of its children.
84+
* Text has lots of new methods to help style it: Text.fill, Text.align, Text.stroke, etc.
85+
* Text now works happily with font names with spaces in them.
86+
* Text.setShadow applies a drop shadow to the Text being rendered. Control the x, y, color and blur.
87+
* Text.lineSpacing allows you to control the spacing between each line that is rendered.
8388

8489

8590
New Examples:

examples/wip/destroy.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }, false);
3+
4+
function preload() {
5+
6+
game.load.image('pic', 'assets/pics/backscroll.png');
7+
8+
}
9+
10+
var sprite;
11+
var sprite2;
12+
var g;
13+
var p;
14+
15+
function create() {
16+
17+
game.stage.backgroundColor = '#ff5500';
18+
19+
game.renderer.useFillRect = false;
20+
21+
sprite = game.add.sprite(0.5, 0, 'pic');
22+
sprite2 = game.add.sprite(0, 300, 'pic');
23+
24+
game.input.onDown.add(tint, this);
25+
26+
// game.add.tween(sprite).to({y: 500}, 3000, Phaser.Easing.Linear.None, true);
27+
28+
// p = new PIXI.Point(43, 45);
29+
30+
}
31+
32+
function tint() {
33+
34+
sprite.destroy();
35+
// sprite.tint = Math.random() * 0xFFFFFF;
36+
// sprite2.tint = Math.random() * 0xFFFFFF;
37+
38+
}
39+
40+
function update() {
41+
42+
43+
}
44+
45+
function render() {
46+
47+
// game.debug.renderText(sprite.position.y, 32, 32);
48+
49+
}

examples/wip/pixi1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ var p;
1414

1515
function create() {
1616

17-
// game.stage.backgroundColor = '#ff5500';
17+
game.stage.backgroundColor = '#ff5500';
18+
19+
game.renderer.useFillRect = false;
1820

1921
sprite = game.add.sprite(0.5, 0, 'pic');
2022

@@ -29,7 +31,7 @@ function create() {
2931

3032
// game.input.onDown.add(tint, this);
3133

32-
// game.add.tween(sprite).to({y: 500}, 3000, Phaser.Easing.Linear.None, true);
34+
game.add.tween(sprite).to({y: 500}, 3000, Phaser.Easing.Linear.None, true);
3335

3436
p = new PIXI.Point(43, 45);
3537

examples/wip/text.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }, false);
3+
// var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create, update: update, render: render }, false);
4+
5+
function preload() {
6+
7+
game.load.image('pic', 'assets/pics/backscroll.png');
8+
9+
}
10+
11+
var text;
12+
13+
function create() {
14+
15+
game.stage.backgroundColor = '#c48844';
16+
17+
text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nwith a sprinkle of\npixi dust");
18+
19+
text.anchor.setTo(0.5);
20+
21+
text.font = 'Art of Fighting 2';
22+
// text.font = 'Arial';
23+
text.fontSize = 40;
24+
// text.fontWeight = 'bold italic';
25+
26+
// x0, y0 - x1, y1
27+
var grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height);
28+
29+
grd.addColorStop(0, '#8ED6FF');
30+
grd.addColorStop(1, '#004CB3');
31+
32+
// text.fill = '#ff0044';
33+
// text.lineSpacing = 16;
34+
text.fill = grd;
35+
text.align = 'center';
36+
text.stroke = '#ff00ff';
37+
text.strokeThickness = 2;
38+
39+
text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5);
40+
41+
game.input.onDown.add(change, this);
42+
43+
}
44+
45+
function change() {
46+
47+
text.tint = Math.random() * 0xFFFFFF;
48+
49+
}
50+
51+
function update() {
52+
53+
54+
}
55+
56+
function render() {
57+
58+
// game.debug.renderText(sprite.position.y, 32, 32);
59+
60+
}

src/core/World.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Phaser.World.prototype.boot = function () {
6464

6565
/**
6666
* This is called automatically after the plugins preUpdate and before the State.update.
67-
* Most objects have preUpdate methods and it's where initial movement, drawing and calculations are done.
67+
* Most objects have preUpdate methods and it's where initial movement and positioning is done.
6868
*
6969
* @method Phaser.World#preUpdate
7070
*/

0 commit comments

Comments
 (0)