Phaser Example Series

Adding Text in Phaser and spicing up text with Tweens.

by Dillybob

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.3/phaser.js"></script>
<div id="phaser_example"></div>

JavaScript

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser_example', { preload: preload, create: create, update: update, render: render});
function preload() {
 
    game.load.script('filter', 'https://cdn.rawgit.com/photonstorm/phaser/master/filters/Fire.js');

}

function create() {

	//game.load.image('background','./img/starb.png');
    game.time.advancedTiming = true;
    
    
    game.load.script('filter', 'https://cdn.rawgit.com/photonstorm/phaser/master/filters/Fire.js');
    
    
   									var drawnObject;
									var bar_width = 250
					 
									var bar_height = 20;
									var bar_line_width = 4;
									var bmd = game.add.bitmapData(bar_width, bar_height);
									// 4. Draw grahpics.

									bmd.ctx.rect(0,0, bar_width, bar_height);

									bmd.ctx.fillStyle="#fff";
									bmd.ctx.fillRect(0,0, bar_width, bar_height);

									bmd.ctx.lineWidth = bar_line_width;
									 
									//ctx.globalCompositeOperation = 'destination-atop';
									bmd.ctx.stroke();
									 
									drawnObject = game.add.sprite(250, 144, bmd);
									 
									drawnObject.angle = 33;
									drawnObject.alpha = 1;
									drawnObject.inputEnabled = false;
    
    background = game.add.sprite(0, 0);
	background.width = 800;
	background.height = 600;
	filter = game.add.filter('Fire', 800, 600);
	filter.alpha = 0.0;
	background.filters = [filter];
    
    
    
    
}


function update(){
 
	filter.update();
 
    game.forceSingleUpdate = true;
    
}

function render(){
    game.debug.text(game.time.fps || '--', 2, 14, "#00ff00"); 
}