-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpixi.html
140 lines (106 loc) · 3.3 KB
/
pixi.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GameStats Pixi Extension example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/6.0.2/browser/pixi.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pixi-spine.umd.min.js"></script>
<script src="../build/gamestats.js"></script>
<style>
html, body, canvas{
width:100%;
height:100%;
margin: 0;
padding:0;
color:white;
}
html{
background:#000;
}
div[data="gamestats"], button{
margin: 20px;
filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.3));
}
</style>
</head>
<body>
<script>
const app = new PIXI.Application();
document.body.appendChild(app.view);
const stats = new GameStats();
stats.dom.style.top = '0%';
stats.dom.style.left = '0%';
stats.enableExtension('pixi', [PIXI, app])
app.stop(); // custom render
// load spine data
app.loader
.add('pixie', 'https://pixijs.io/examples/examples/assets/pixi-spine/pixie.json')
.load(onAssetsLoaded);
let postition = 0;
let background;
let background2;
let foreground;
let foreground2;
app.stage.interactive = true;
function onAssetsLoaded(loader, res) {
background = PIXI.Sprite.from('https://pixijs.io/examples/examples/assets/pixi-spine/iP4_BGtile.jpg');
background2 = PIXI.Sprite.from('https://pixijs.io/examples/examples/assets/pixi-spine/iP4_BGtile.jpg');
foreground = PIXI.Sprite.from('https://pixijs.io/examples/examples/assets/pixi-spine/iP4_ground.png');
foreground2 = PIXI.Sprite.from('https://pixijs.io/examples/examples/assets/pixi-spine/iP4_ground.png');
foreground.anchor.set(0, 0.7);
foreground.position.y = app.screen.height;
foreground2.anchor.set(0, 0.7);
foreground2.position.y = app.screen.height;
app.stage.addChild(background, background2, foreground, foreground2);
const pixie = new PIXI.spine.Spine(res.pixie.spineData);
const scale = 0.3;
pixie.x = 1024 / 3;
pixie.y = 500;
pixie.scale.x = pixie.scale.y = scale;
app.stage.addChild(pixie);
pixie.stateData.setMix('running', 'jump', 0.2);
pixie.stateData.setMix('jump', 'running', 0.4);
pixie.state.setAnimation(0, 'running', true);
app.stage.on('pointerdown', onTouchStart);
function onTouchStart() {
pixie.state.setAnimation(0, 'jump', false);
pixie.state.addAnimation(0, 'running', true, 0);
}
ticker.start();
}
var ticker = new PIXI.Ticker();
ticker.add(() => {
stats.begin();
postition += 10;
background.x = -(postition * 0.6);
background.x %= 1286 * 2;
if (background.x < 0) {
background.x += 1286 * 2;
}
background.x -= 1286;
background2.x = -(postition * 0.6) + 1286;
background2.x %= 1286 * 2;
if (background2.x < 0) {
background2.x += 1286 * 2;
}
background2.x -= 1286;
foreground.x = -postition;
foreground.x %= 1286 * 2;
if (foreground.x < 0) {
foreground.x += 1286 * 2;
}
foreground.x -= 1286;
foreground2.x = -postition + 1286;
foreground2.x %= 1286 * 2;
if (foreground2.x < 0) {
foreground2.x += 1286 * 2;
}
foreground2.x -= 1286;
app.render();
stats.end();
}, PIXI.UPDATE_PRIORITY.LOW);
</script>
</body>
</html>