-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathText_simple.html
executable file
·78 lines (61 loc) · 1.92 KB
/
Text_simple.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EaselJS Example: Text</title>
<link href="../_assets/css/shared.css" rel="stylesheet" type="text/css"/>
<link href="../_assets/css/examples.css" rel="stylesheet" type="text/css"/>
<script src="../_assets/js/examples.js"></script>
<script src="../lib/easeljs-NEXT.js"></script>
<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->
<script id="editable">
var canvas;
var stage;
var txt;
var shape;
var count = 0;
function init() {
//find canvas and load images, wait for last image to load
canvas = document.getElementById("testCanvas");
stage = new createjs.Stage(canvas);
// Create a new Text object, and position it on stage:
txt = new createjs.Text("text on the canvas... 0!", "36px Arial", "#FFF");
txt.x = 100;
txt.y = 80;
txt.rotation = 20;
//txt.outline = true;
stage.addChild(txt);
// this shape will be the background for the text:
shape = new createjs.Shape();
shape.x = txt.x;
shape.y = txt.y;
shape.rotation = txt.rotation;
stage.addChildAt(shape, 0);
// we want to do some work before we update the canvas,
// otherwise we could use Ticker.addEventListener("tick", stage);
createjs.Ticker.framerate = 100;
createjs.Ticker.addEventListener("tick", tick);
}
function tick(event) {
count++;
// update the text:
txt.text = "text on the canvas... " + count + "!";
// draw a vector box of the appropriate width behind the text:
shape.graphics.clear().beginFill("#F00").drawRect(-10, -10, txt.getMeasuredWidth() + 20, 36 + 20);
// update the stage:
stage.update(event);
}
</script>
</head>
<body onload="init();">
<header class="EaselJS">
<h1>Text Sample</h1>
<p>Shows how to use <code>Text</code> elements, and <code>Text.getMeasuredWidth()</code>.
</p>
</header>
<div>
<canvas id="testCanvas" width="960" height="400"></canvas>
</div>
</body>
</html>