-
Notifications
You must be signed in to change notification settings - Fork 33
/
Phasor-Demo.html
181 lines (141 loc) · 6.18 KB
/
Phasor-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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>hello phaser!</title>
<script src="phaser-2.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="CreaturePixiJSRenderer.js"></script>
<script src="CreaturePhaserRenderer.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
var game = new Phaser.Game(800, 600, Phaser.WEBGL, '', { preload: preload, create: create, update: update});
var texture = null;
var new_creature = null;
var new_animation_1 = null;
var new_animation_2 = null;
var new_manager = null;
var creaturePhasorObject = null;
// For testing
var new_manager2 = null;
var creaturePhasorObject2 = null;
function preload () {
game.load.text('iceJSON', 'iceDemonExport_character_data.json');
//game.load.binary('iceBin', 'iceDemonExport_character_data.bytes', binaryLoadCallback, this);
// create a texture from an image path
//game.load.image('succTexture', 'debug3Export_character_img.png');
game.load.image('iceDemonTexture', 'iceDemonExport_character_img.png');
}
function binaryLoadCallback(key, data) {
// Convert our binary file into a Uint8Array
// We must return the data value or nothing will be added to the cache, even if you don't modify it.
return new Uint8Array(data);
}
function initDebugging()
{
bmd = game.add.bitmapData(800,600);
sprite = game.add.sprite(0, 0, bmd);
}
function create () {
// Grab actual texture for rendering
texture = new PIXI.Texture(game.cache.getBaseTexture('iceDemonTexture'));
initDebugging();
// Core Creature Objects
var actual_data = JSON.parse(game.cache.getText('iceJSON').slice(0)); // Make a copy/clone of the input JSON string
//var actual_data = CreatureModuleUtils.LoadCreatureFlatData(game.cache.getBinary('iceBin').slice(0));
new_creature = new Creature(actual_data, false);
//new_creature.anchor_points_active = false;
//new_creature = new Creature(actual_data, true);
//new_animation_1 = new CreatureAnimation(actual_data, "idle", new_creature);
//new_animation_2 = new CreatureAnimation(actual_data, "back", new_creature);
//new_animation_1 = new CreatureAnimation(actual_data, "idle", true);
//new_animation_1 = new CreatureAnimation(actual_data, "default", true);
new_animation_1 = new CreatureAnimation(actual_data, "default", false);
new_manager = new CreatureManager(new_creature);
new_manager.AddAnimation(new_animation_1);
new_manager.SetActiveAnimationName("default", false);
//new_manager.AddAnimation(new_animation_2);
//new_manager.SetActiveAnimationName("idle", false);
//new_manager.SetAutoBlending(true);
//new_manager.AutoBlendTo("back", 0.01);
//new_manager.SetActiveAnimationName("back", false);
new_manager.SetShouldLoop(true);
new_manager.SetIsPlaying(true);
// Test point caching
//new_manager.MakePointCache("default");
// Test point fill caching
/*
for(var i = 350; i <= 500; i++)
{
new_manager.FillSinglePointCacheFrame("default", i);
}
*/
console.log('Loaded and created Core Creature Objects.');
// Phasor Creature Object
creaturePhasorObject = new Phaser.CreatureDraw(game.world,
game.world.centerX,
game.world.centerY,
new_manager,
texture);
new_manager.RunAtTime(0);
var pixelScale = creaturePhasorObject.GetPixelScaling(600, 650);
creaturePhasorObject.scale.set(pixelScale[0], pixelScale[1]);
//creaturePhasorObject.scale.set(35.0);
creaturePhasorObject.timeDelta = 0.035;
game.world.add(creaturePhasorObject);
// Second object for testing
/*
new_manager2 = new CreatureManager(new_creature);
new_manager2.AddAnimation(new_animation_1);
//new_manager2.AddAnimation(new_animation_2);
new_manager2.SetActiveAnimationName("default", false);
new_manager2.SetShouldLoop(true);
new_manager2.SetIsPlaying(true);
new_manager2.RunAtTime(0);
creaturePhasorObject2 = new Phaser.CreatureDraw(game.world,
game.world.centerX,
game.world.centerY,
new_manager2,
texture);
creaturePhasorObject2.scale.set(15.0);
creaturePhasorObject2.timeDelta = 0.1;
game.world.add(creaturePhasorObject2);
*/
}
function update() {
// for debugging
// draw boundary rectangles
/*
var target_creature = creaturePhasorObject.creature_manager.target_creature;
bmd.clear();
var dbgPt = new PIXI.Point(0,0);
for(var i = 0; i < target_creature.boundary_indices.length; i++)
{
var ref_idx = target_creature.boundary_indices[i] * 3;
var ref_x = target_creature.render_pts[ref_idx];
var ref_y = target_creature.render_pts[ref_idx + 1];
dbgPt.set(ref_x, -ref_y);
creaturePhasorObject.worldTransform.apply(dbgPt, dbgPt);
bmd.ctx.fillStyle = "rgb(200,0,0)";
bmd.ctx.fillRect(dbgPt.x, dbgPt.y, 5, 5);
}
bmd.ctx.beginPath();
bmd.ctx.strokeStyle = "white";
bmd.ctx.lineWidth = 10;
bmd.ctx.rect(creaturePhasorObject.creatureBoundsMin.x,
creaturePhasorObject.creatureBoundsMin.y,
creaturePhasorObject.creatureBoundsMax.x - creaturePhasorObject.creatureBoundsMin.x,
creaturePhasorObject.creatureBoundsMax.y - creaturePhasorObject.creatureBoundsMin.y);
bmd.ctx.stroke();
bmd.dirty = true;
*/
}
};
</script>
</body>
</html>