-
Notifications
You must be signed in to change notification settings - Fork 1
/
jixi.js
122 lines (91 loc) · 3.53 KB
/
jixi.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
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
// PixiJS convenience aliases
window.Sprite = PIXI.Sprite;
window.Point = PIXI.Point;
window.Rectangle = PIXI.Rectangle;
window.Text = PIXI.Text
window.Graphics = PIXI.Graphics
window.Container = PIXI.Container;
window.loader = PIXI.Loader.shared; //PIXI.Loader.shared; //. new PIXI.Loader(); // Using shared was causing bug with hot reload.
window.resources = loader.resources;
window.ticker = PIXI.Ticker.shared;
import * as _ext from './utils/extensions.js'
import * as utils from './utils/utils.js';
import Scene from './class/scene.js';
import Camera from './class/camera.js';
import Btn from './class/btn.js';
import * as nav from './core/nav.js';
import * as scaler from './core/scaler.js';
import * as ui from './core/ui.js';
import KB from './core/kb.js';
const kb = new KB();
// Props
let pixiApp; // PIXI app instance
let isProd = process.env.NODE_ENV != 'development'; // Set in package.json: eg. "start:dev": "webpack serve --mode development"
let htmlEle; // The element containing the game
// Load all transitions
let filters = {};
const _filters = utils.requireAll(require.context('./filters', false, /.js$/));
for (let _filter of _filters) {
filters[_filter.id] = _filter.default;
}
//let stageW = 0; // Stage dims
//let stageH = 0; // Stage dims
export function createApp(_htmlEle, fullScreen = false, bgAlpha = 1.0, bgColor = 0x000000, onLoadCallback = null) {
htmlEle = _htmlEle;
// Docs: http://pixijs.download/release/docs/PIXI.Application.html#Application
pixiApp = new PIXI.Application({
// width: window.innerWidth,
// height: window.innerHeight,
autoDensity: true, // Adjusts the canvas using css pixels so it will scale properly (it was the default behavior in v4)
antialias: window.devicePixelRatio == 1, //(),
transparent: bgAlpha < 1.0,
resolution: window.devicePixelRatio, // Resolution controls scaling of content (sprites, etc.)
resizeTo: fullScreen ? window : htmlEle,
backgroundColor: bgColor,
clearBeforeRender: true
});
pixiApp.render()
scaler.setup();
ui.loadAssets(function(){
setup(bgAlpha);
if (onLoadCallback){
onLoadCallback(pixiApp);
}
})
}
// All assets are loaded by this point and the stage is empty
function setup(bgAlpha){
// Attach canvas to the DOM
htmlEle.appendChild(pixiApp.view);
//app.view.style.pointerEvents = 'auto';
//htmlEle.style.pointerEvents = 'none';
// gsap.set(pixiApp.view, {opacity:0.999})
// Attach core display objects
nav.setupStage(pixiApp.stage, bgAlpha);
// Debug TF
if (isProd){
// Disable right click - this menu may be confusing to user
htmlEle.setAttribute('oncontextmenu', 'return false');
} else {
const debugTf = new PIXI.Text('X', {fontFamily : 'Arial', fontSize: 13, fill : 0xffffff, align : 'left', dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 0.0,
dropShadowDistance: 2.0});
debugTf.x = 3.0;
debugTf.y = 3.0; //+ 50.0;
debugTf.alpha = 0.5;
pixiApp.stage.addChild(debugTf);
ticker.add(function(time){
debugTf.text = PIXI.Ticker.shared.FPS.toFixed(2);
});
}
// Get default scene and load it
if (!nav.openDefaultScene()){
throw new Error('Default scene not found.')
}
}
// export {stageW, stageH} from './core/scaler.js'; // Convenience alias
export {pixiApp, filters};
export {Scene, Camera, Btn}; // Classes
export {kb}// Helpers
export {utils, nav, ui, scaler}; // Core