/
init.js
67 lines (55 loc) · 2.07 KB
/
init.js
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
// key event to close application
// this is a experimental implementation until the game has a quit buttons
$("html").keyup(function(e){
if (e.which == 27){
// Load native UI library
var gui = require('nw.gui');
gui.App.closeAllWindows();
}
});
// use init function from base
baseInit();
baseValues.display = {
width: 1280, // do not change this value, or you have to change all assets too!
height: 1024, // do not change this value, or you have to change all assets too!
ratio: 0
}; // display properties, width / height / ratio will be overwritten
baseValues.pixi = {}; // contains render / stage of pixi
// add all assets here!
baseValues.assetsToLoad = [
"gfx/mct_logo.png"
];
$(document).ready(function() {
global.setTimeout(displayInit, 10); // use timeout to detect fullscreen size correctly
function displayInit() {
// create an new instance of a pixi stage
baseValues.pixi.stage = new PIXI.Stage(0x66FF99);
// create a renderer instance.
baseValues.pixi.renderer = PIXI.autoDetectRenderer(
baseValues.display.width, baseValues.display.height
);
// add the renderer view element to the DOM
document.body.appendChild(baseValues.pixi.renderer.view);
// resize display size by current window size
baseValues.display.ratio = Math.min(
window.innerWidth / baseValues.display.width,
window.innerHeight / baseValues.display.height
);
baseValues.display.width = baseValues.display.width * baseValues.display.ratio;
baseValues.display.height = baseValues.display.height * baseValues.display.ratio;
baseValues.pixi.renderer.resize(baseValues.display.width, baseValues.display.height);
// init / run animation function
requestAnimFrame(animate);
function animate() {
requestAnimFrame(animate);
// render the stage
baseValues.pixi.renderer.render(baseValues.pixi.stage);
}
// create a new loader
loader = new PIXI.AssetLoader(baseValues.assetsToLoad);
delete baseValues.assetsToLoad;
loader.onComplete = displayLogoAdd;
//begin load
loader.load();
}
});