Example 6. Text

A text is added to the screen around the center point.


It is styled using Tarzan font.


This is the javascript file:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ex06. Text

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'ex06',
               {create: create});

function create() {
    // Set backgound color
    game.stage.backgroundColor = "#0FFF0F";

    // Style for text
    var style = {
        font: 'bold 50pt Tarzan',
        fill: '#D0171B',
        align: 'center'
    }
    
    // center coordinates
    var x = game.world.centerX;
    var y = game.world.centerY;

    // Show text with x,y the center point
    text = game.add.text(x, y, 'Hello\nPhaser\nWorld', style);
    text.anchor.setTo(0.5);
}



This is the output:




No comments:

Post a Comment