From bcd31499c44e351c69583b9f6623ec31cf8a8671 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 14 Feb 2014 17:08:25 +0000 Subject: [PATCH] Couple of new labs tests. --- examples/wip/text.js | 42 +++++++++++++------------- labs/code/006 bitmap fonts ahoy.js | 36 +++++++++++++++++++++++ labs/code/007 text shadow.js | 47 ++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 labs/code/006 bitmap fonts ahoy.js create mode 100644 labs/code/007 text shadow.js diff --git a/examples/wip/text.js b/examples/wip/text.js index c32c2d18..c5c80457 100644 --- a/examples/wip/text.js +++ b/examples/wip/text.js @@ -1,6 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }, false); -// var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create, update: update, render: render }, false); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { @@ -10,36 +9,37 @@ function preload() { var text; var b; +var grd; function create() { - game.stage.backgroundColor = '#2d2d2d'; + game.stage.setBackgroundColor(0x2d2d2d); - // text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nwith a sprinkle of\npixi dust"); - text = game.add.text(game.world.centerX, game.world.centerY, "- phaser - with a sprinkle of pixi dust"); + text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nwith a sprinkle of\npixi dust"); + // text = game.add.text(game.world.centerX, game.world.centerY, "- phaser - with a sprinkle of pixi dust"); text.anchor.setTo(0.5); - text.font = 'Art of Fighting 2'; - // text.font = 'Arial'; - text.fontSize = 30; - // text.fontWeight = 'bold italic'; + // text.font = 'Art of Fighting 2'; + text.font = 'Arial Black'; + text.fontSize = 60; + text.fontWeight = 'bold'; // x0, y0 - x1, y1 - // var grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height); - // grd.addColorStop(0, '#8ED6FF'); - // grd.addColorStop(1, '#004CB3'); - // text.fill = grd; + grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height); + grd.addColorStop(0, '#8ED6FF'); + grd.addColorStop(1, '#004CB3'); + text.fill = grd; - text.fill = '#ff0044'; + // text.fill = '#ff0044'; // text.lineSpacing = 16; text.align = 'center'; text.stroke = '#000000'; text.strokeThickness = 2; - // text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5); - text.wordWrap = true; - text.wordWrapWidth = 50; + text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5); + // text.wordWrap = true; + // text.wordWrapWidth = 50; // game.input.onDown.add(change, this); @@ -53,7 +53,7 @@ function create() { function out() { - text.fill = '#ff0044'; + text.fill = grd; } @@ -65,19 +65,19 @@ function over() { function change() { - text.tint = Math.random() * 0xFFFFFF; + // text.tint = Math.random() * 0xFFFFFF; } function update() { - b = text.getBounds(); + // b = text.getBounds(); } function render() { - game.debug.renderRectangle(b); + // game.debug.renderRectangle(b); // game.debug.renderText(sprite.position.y, 32, 32); } diff --git a/labs/code/006 bitmap fonts ahoy.js b/labs/code/006 bitmap fonts ahoy.js new file mode 100644 index 00000000..6af0d0bb --- /dev/null +++ b/labs/code/006 bitmap fonts ahoy.js @@ -0,0 +1,36 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); + +function preload() { + + game.load.image('knightHawks', 'assets/fonts/KNIGHT3.png'); + +} + +var font; +var i; + +function create() { + + font = game.add.bitmapFont('knightHawks', 31, 25, Phaser.BitmapFont.TEXT_SET6, 10, 1, 1); + font.text = 'phaser was here'; + + for (var c = 0; c < 19; c++) + { + var i = game.add.image(game.world.centerX, c * 32, font); + + if (game.renderType === Phaser.WEBGL) + { + i.tint = Math.random() * 0xFFFFFF; + } + + i.anchor.set(0.5, 1); + } + +} + +function update() { + + font.text = "phaser x: " + game.input.x + " y: " + game.input.y; + +} diff --git a/labs/code/007 text shadow.js b/labs/code/007 text shadow.js new file mode 100644 index 00000000..486d6850 --- /dev/null +++ b/labs/code/007 text shadow.js @@ -0,0 +1,47 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create }); + +var text; +var grd; + +function create() { + + game.stage.setBackgroundColor(0x2d2d2d); + + text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nwith a sprinkle of\npixi dust"); + text.anchor.setTo(0.5); + + text.font = 'Arial Black'; + text.fontSize = 60; + text.fontWeight = 'bold'; + + grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height); + grd.addColorStop(0, '#8ED6FF'); + grd.addColorStop(1, '#004CB3'); + text.fill = grd; + + text.align = 'center'; + text.stroke = '#000000'; + text.strokeThickness = 2; + + text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5); + + text.inputEnabled = true; + text.input.enableDrag(); + + text.events.onInputOver.add(over, this); + text.events.onInputOut.add(out, this); + +} + +function out() { + + text.fill = grd; + +} + +function over() { + + text.fill = '#ff00ff'; + +}