-
Notifications
You must be signed in to change notification settings - Fork 33
/
PixiJs-Demo.html
117 lines (85 loc) · 3.62 KB
/
PixiJs-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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PixiJs - Basic scene</title>
<style>
canvas {
border: 1px dashed gray;
}
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script src="pixi.js"></script>
<script src="gl-matrix.js"></script>
<script src="flatbuffers.js"></script>
<script src="CreatureFlatData_generated.js"></script>
<script src="CreatureMeshBone.js"></script>
<script src="CreaturePixiJSRefRenderer.js"></script>
<script>
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
//xobj.open('GET', 'debug3Export_character_data.json', true); // Replace 'my_data' with the path to your file
// Artwork by: Katarzyna Zalecka [http://kasia88.deviantart.com], Attribution-ShareAlike 3.0 Unported
// Download Asset Files here: http://www.kestrelmoon.com/creaturedocs/Animation_Samples_And_Examples/Samples_And_Videos.html
xobj.open('GET', 'iceDemonExport_character_data.json', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
// callback(xobj.responseText);
var response = xobj.responseText;
// Parse JSON string into object
var actual_JSON = JSON.parse(response);
//document.write("Loaded JSON file: ");
var new_creature = new Creature(actual_JSON, false);
var new_animation_1 = new CreatureAnimation(actual_JSON, "default", false);
//var new_animation_1 = new CreatureAnimation(actual_JSON, "idle", false);
//var new_animation_2 = new CreatureAnimation(actual_JSON, "back", false);
var new_manager = new CreatureManager(new_creature);
new_manager.AddAnimation(new_animation_1);
//new_manager.AddAnimation(new_animation_2);
//new_manager.SetActiveAnimationName("idle", false);
new_manager.SetActiveAnimationName("default", false);
new_manager.SetShouldLoop(true);
new_manager.SetIsPlaying(true);
new_manager.RunAtTime(0);
// create an new instance of a pixi stage
var stage = new PIXI.Container();
// create a renderer instance.
var renderer = new PIXI.Renderer(window.innerWidth, window.innerHeight);
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
// create a texture from an image path
//var texture = PIXI.Texture.fromImage("debug3Export_character_img.png");
var texture = PIXI.Texture.fromImage("iceDemonExport_character_img.png");
var creatureContainer = new PIXI.Container();
creatureContainer.position.x = window.innerWidth/3;
creatureContainer.position.y = window.innerHeight/3;
creatureContainer.scale.set(25.0);
stage.addChild(creatureContainer);
var new_creature_renderer = new CreatureRenderer(new_manager, texture);
creatureContainer.addChild(new_creature_renderer);
creatureContainer.scale.x = creatureContainer.scale.x;
function animate() {
requestAnimationFrame( animate );
new_manager.Update(0.025);
new_creature_renderer.refresh();
// render the stage
renderer.render(stage);
}
animate();
}
};
xobj.send(null);
</script>
</body>
</html>