-
Notifications
You must be signed in to change notification settings - Fork 33
/
PixiJSRef-Pack-Demo.html
68 lines (55 loc) · 2.25 KB
/
PixiJSRef-Pack-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
67
68
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>CreaturePack WebAssembly Demo</title>
<script src="pixi.js"></script>
<script src="msgpack.js"></script>
<script src="CreaturePackModule.js"></script>
<script src="CreaturePackPixiJSRefRenderer.js"></script>
</head>
<body>
<script type="text/javascript">
var loadFile = function (filePath, done) {
var xhr = new XMLHttpRequest();
xhr.onload = function () { return done(this.response); };
xhr.open("GET", filePath, true);
xhr.responseType = "arraybuffer";
xhr.send();
};
window.onload = function() {
loadFile("fox2x.creature_pack", function(response) {
var byte_array = new Uint8Array(response);
console.log("Loaded CreaturePack Data with size: " + byte_array.byteLength);
creature_pack = new CreaturePackLoader(byte_array.buffer);
var texture = PIXI.Texture.from("fox.png");
// Start PixiJS
// create a renderer instance.
var renderer = new PIXI.Renderer(window.innerWidth, window.innerHeight);
//Create a container object called the `stage`
var stage = new PIXI.Container();
// Add the renderer view element to the DOM
document.body.appendChild(renderer.view);
// Add CreaturePack objects
var creatureContainer = new PIXI.Container();
creatureContainer.position.x = window.innerWidth/4;
creatureContainer.position.y = window.innerHeight/2;
creatureContainer.scale.set(15.0);
stage.addChild(creatureContainer);
var raptor_renderer = new CreaturePackRenderer(creature_pack, texture);
raptor_renderer.pack_renderer.setActiveAnimation("run");
creatureContainer.addChild(raptor_renderer);
creatureContainer.scale.x = creatureContainer.scale.x;
function animate() {
requestAnimationFrame( animate );
raptor_renderer.pack_renderer.stepTime(1.0);
raptor_renderer.refresh();
// render the stage
renderer.render(stage);
}
animate();
});
};
</script>
</body>
</html>