forked from quidmonkey/Canvas-Native-Fonts-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
59 lines (46 loc) · 1.58 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Font Plugin Example
* Written by Abraham Walters
* May 2012
*/
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font',
'plugins.font'
)
.defines(function(){
FontExample = ig.Game.extend({
fireFont: new Font( '20px Garamond' ), //animated font
font: new Font( '20px Garamond' ), //basic font
init: function(){
ig.input.bind( ig.KEY.SPACE, 'prompt' );
//add array of colors to font to animate through
this.fireFont.colors = ['#FF0000', '#FF6600', '#FFFF00', '#FFFFFF' ];
},
draw: function() {
ig.system.clear( this.clearColor );
var x = ig.system.width / 2 - this.font.getWidth() / 2,
y = ig.system.height / 2,
offset = this.font.size * 1.5;
//draw font with various parameters
this.font.draw( 'Hello World', x, y - offset ); //left align, white coloring
this.font.draw( 'Hello World', x, y, 'right' ); //white coloring
this.font.draw( 'Hello World', x, y + offset, 'center', '#FF0000' );
//draw animated font
this.fireFont.draw( 'Hello World', x, y + offset * 2, 'center' );
},
update: function(){
//if space is pressed, allow user to enter new font type
if( ig.input.pressed( 'prompt' ) ){
this.font.font = prompt( 'Enter New Font Type:', this.font.font ) || this.font.font;
this.fireFont.font = this.font.font;
}
//animate through font colors
this.fireFont.update();
}
});
ig.main( '#canvas', FontExample, 60, 320, 240, 2 );
});