forked from karellodewijk/karellodewijk.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
66 lines (60 loc) · 1.92 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/3.0.9/pixi.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<title>demo</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
$(document).ready(function() {
var renderer = PIXI.autoDetectRenderer(1000,1000,{backgroundColor : 0xEEEEEE});
$("body").append(renderer.view);
var stage = new PIXI.Container();
//set a background
var background_sprite = new PIXI.Sprite();
background_sprite.height = renderer.height;
background_sprite.width = renderer.width;
var empty_backround = new PIXI.Graphics();
empty_backround.beginFill(0xEEEEEE, 1);
empty_backround.moveTo(0, 0);
empty_backround.lineTo(renderer.width, 0);
empty_backround.lineTo(renderer.width, renderer.height);
empty_backround.lineTo(0, renderer.height);
empty_backround.lineTo(0, 0);
empty_backround.endFill();
background_sprite.texture = empty_backround.generateTexture();
stage.addChild(empty_backround);
renderer.render(stage);
var graphic;
var last_x, last_y;
function start(e) {
var mouse_location = e.data.getLocalPosition(stage);
graphic = new PIXI.Graphics();
graphic.lineStyle(4, 0x000000, 1);
last_x = mouse_location.x, last_y = mouse_location.y;
graphic.moveTo(mouse_location.x, mouse_location.y);
stage.addChild(graphic);
stage.mousemove = move;
stage.mouseup = end;
}
function move(e) {
var mouse_location = e.data.getLocalPosition(stage);
graphic.moveTo(last_x, last_y);
graphic.lineTo(mouse_location.x, mouse_location.y);
last_x = mouse_location.x, last_y = mouse_location.y;
renderer.render(stage);
}
function end() {
stage.removeChild(graphic);
renderer.render(stage);
delete stage.mousemove;
delete stage.mouseup;
}
stage.interactive = true;
stage.mousedown = start;
});
</script>