littlejsengine 1.18.28 → 1.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FAQ.md +5 -0
- package/README.md +207 -199
- package/dist/littlejs.d.ts +2099 -48
- package/dist/littlejs.esm.js +16251 -10315
- package/dist/littlejs.esm.min.js +13 -1
- package/dist/littlejs.js +15747 -9888
- package/dist/littlejs.min.js +13 -1
- package/dist/littlejs.release.js +15719 -9867
- package/package.json +1 -1
- package/plugins/audioEffects.js +371 -0
- package/plugins/lightSystem.js +5 -3
- package/plugins/math3d.js +870 -0
- package/plugins/medalSystem.js +280 -280
- package/plugins/pluginExport.js +181 -115
- package/plugins/postProcess.js +241 -166
- package/plugins/render3d.js +4006 -0
- package/plugins/textureSheet.js +458 -458
- package/plugins/threejs.js +6 -1
- package/plugins/tweenSystem.js +528 -526
- package/plugins/zzfxm.js +159 -166
- package/src/engine.js +172 -137
- package/src/engineAudio.js +918 -775
- package/src/engineBuild.mjs +3 -0
- package/src/engineDebug.js +15 -8
- package/src/engineDraw.js +1672 -1510
- package/src/engineExport.js +407 -396
- package/src/engineInput.js +1 -1
- package/src/engineLogo.js +4 -3
- package/src/engineMath.js +69 -0
- package/src/engineObject.js +560 -551
- package/src/engineSettings.js +759 -725
- package/src/engineTileLayer.js +3 -3
- package/src/engineUtilities.js +13 -0
- package/src/engineWebGL.js +1005 -941
package/src/engineSettings.js
CHANGED
|
@@ -1,726 +1,760 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LittleJS Engine Settings
|
|
3
|
-
* - All settings for the engine are here
|
|
4
|
-
* @namespace Settings
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
10
|
-
// Camera settings
|
|
11
|
-
|
|
12
|
-
/** Position of camera in world space
|
|
13
|
-
* @type {Vector2}
|
|
14
|
-
* @default Vector2()
|
|
15
|
-
* @memberof Settings */
|
|
16
|
-
let cameraPos = vec2();
|
|
17
|
-
|
|
18
|
-
/** Rotation angle of camera in world space
|
|
19
|
-
* @type {number}
|
|
20
|
-
* @default
|
|
21
|
-
* @memberof Settings */
|
|
22
|
-
let cameraAngle = 0;
|
|
23
|
-
|
|
24
|
-
/** Scale of camera in world space
|
|
25
|
-
* @type {number}
|
|
26
|
-
* @default
|
|
27
|
-
* @memberof Settings */
|
|
28
|
-
let cameraScale = 32;
|
|
29
|
-
|
|
30
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
31
|
-
// Time settings
|
|
32
|
-
|
|
33
|
-
/** Scale applied to engine time, can be used for slow motion or fast forward
|
|
34
|
-
* - 1 is normal speed, 2 is double speed, 0.5 is half speed
|
|
35
|
-
* - 0 freezes the simulation without setting the paused flag
|
|
36
|
-
* - Should be >= 0; stacks multiplicatively with the debug +/- shortcut
|
|
37
|
-
* @type {number}
|
|
38
|
-
* @default
|
|
39
|
-
* @memberof Settings */
|
|
40
|
-
let timeScale = 1;
|
|
41
|
-
|
|
42
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
43
|
-
// Display settings
|
|
44
|
-
|
|
45
|
-
/** Enable applying color to tiles when using canvas2d
|
|
46
|
-
* - This is slower but should be the same as WebGL rendering
|
|
47
|
-
* @type {boolean}
|
|
48
|
-
* @default
|
|
49
|
-
* @memberof Settings */
|
|
50
|
-
let canvasColorTiles = true;
|
|
51
|
-
|
|
52
|
-
/** Color to clear the canvas to before render, does not clear if alpha is 0
|
|
53
|
-
* @type {Color}
|
|
54
|
-
* @memberof Settings */
|
|
55
|
-
let canvasClearColor = CLEAR_BLACK;
|
|
56
|
-
|
|
57
|
-
/** The max size of the canvas, centered if window is larger
|
|
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
|
-
* @type {boolean}
|
|
127
|
-
* @default
|
|
128
|
-
* @memberof Settings */
|
|
129
|
-
let
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* @
|
|
185
|
-
* @
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* @
|
|
191
|
-
* @
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* @
|
|
197
|
-
* @
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* @
|
|
203
|
-
* @
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
* @
|
|
209
|
-
* @
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
* @
|
|
215
|
-
* @
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
* @
|
|
221
|
-
* @
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
* @
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
* @
|
|
236
|
-
* @
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
*
|
|
242
|
-
* @
|
|
243
|
-
* @
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
* @
|
|
250
|
-
* @
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* @type {boolean}
|
|
256
|
-
* @default
|
|
257
|
-
* @memberof Settings */
|
|
258
|
-
let
|
|
259
|
-
|
|
260
|
-
/** True if touch
|
|
261
|
-
* -
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* -
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* @
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
* -
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* @
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
* -
|
|
290
|
-
*
|
|
291
|
-
* @
|
|
292
|
-
* @
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
* -
|
|
298
|
-
* @type {
|
|
299
|
-
* @default
|
|
300
|
-
* @memberof Settings */
|
|
301
|
-
let
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* -
|
|
305
|
-
*
|
|
306
|
-
* @
|
|
307
|
-
* @
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
* -
|
|
313
|
-
*
|
|
314
|
-
* @
|
|
315
|
-
* @
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*
|
|
321
|
-
* @
|
|
322
|
-
* @
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
*
|
|
337
|
-
* @
|
|
338
|
-
* @
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
* @
|
|
344
|
-
* @
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
* @
|
|
350
|
-
* @
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
* @type {number}
|
|
356
|
-
* @default
|
|
357
|
-
* @memberof Settings */
|
|
358
|
-
let
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
*
|
|
362
|
-
* @
|
|
363
|
-
* @
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
* @
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
* @type {
|
|
378
|
-
* @default
|
|
379
|
-
* @memberof Settings */
|
|
380
|
-
let
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
*
|
|
384
|
-
* @
|
|
385
|
-
* @
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
* @
|
|
391
|
-
* @
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
*
|
|
404
|
-
* @
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
/** Set
|
|
413
|
-
* @param {
|
|
414
|
-
* @memberof Settings */
|
|
415
|
-
function
|
|
416
|
-
|
|
417
|
-
/** Set
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
* @param {
|
|
437
|
-
* @memberof Settings */
|
|
438
|
-
function
|
|
439
|
-
|
|
440
|
-
/** Set
|
|
441
|
-
* @param {
|
|
442
|
-
* @memberof Settings */
|
|
443
|
-
function
|
|
444
|
-
|
|
445
|
-
/** Set
|
|
446
|
-
* @param {Vector2} size
|
|
447
|
-
* @memberof Settings */
|
|
448
|
-
function
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* @param {
|
|
452
|
-
* @memberof Settings */
|
|
453
|
-
function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
* @
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
* @memberof Settings */
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
|
|
499
|
-
{
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
* @
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
* @
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
* @
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
* @
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
* @
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
* @
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
* @
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
* @
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
* @
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
* @
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
* @
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
* @
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
* @
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
* @
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
* @
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
* @
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
*
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
*
|
|
641
|
-
|
|
642
|
-
{
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
* @
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
* @
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
* @
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
* @
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
* @
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
* @
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
* @
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
* @
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
* @
|
|
725
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LittleJS Engine Settings
|
|
3
|
+
* - All settings for the engine are here
|
|
4
|
+
* @namespace Settings
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
10
|
+
// Camera settings
|
|
11
|
+
|
|
12
|
+
/** Position of camera in world space
|
|
13
|
+
* @type {Vector2}
|
|
14
|
+
* @default Vector2()
|
|
15
|
+
* @memberof Settings */
|
|
16
|
+
let cameraPos = vec2();
|
|
17
|
+
|
|
18
|
+
/** Rotation angle of camera in world space
|
|
19
|
+
* @type {number}
|
|
20
|
+
* @default
|
|
21
|
+
* @memberof Settings */
|
|
22
|
+
let cameraAngle = 0;
|
|
23
|
+
|
|
24
|
+
/** Scale of camera in world space
|
|
25
|
+
* @type {number}
|
|
26
|
+
* @default
|
|
27
|
+
* @memberof Settings */
|
|
28
|
+
let cameraScale = 32;
|
|
29
|
+
|
|
30
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
31
|
+
// Time settings
|
|
32
|
+
|
|
33
|
+
/** Scale applied to engine time, can be used for slow motion or fast forward
|
|
34
|
+
* - 1 is normal speed, 2 is double speed, 0.5 is half speed
|
|
35
|
+
* - 0 freezes the simulation without setting the paused flag
|
|
36
|
+
* - Should be >= 0; stacks multiplicatively with the debug +/- shortcut
|
|
37
|
+
* @type {number}
|
|
38
|
+
* @default
|
|
39
|
+
* @memberof Settings */
|
|
40
|
+
let timeScale = 1;
|
|
41
|
+
|
|
42
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
43
|
+
// Display settings
|
|
44
|
+
|
|
45
|
+
/** Enable applying color to tiles when using canvas2d
|
|
46
|
+
* - This is slower but should be the same as WebGL rendering
|
|
47
|
+
* @type {boolean}
|
|
48
|
+
* @default
|
|
49
|
+
* @memberof Settings */
|
|
50
|
+
let canvasColorTiles = true;
|
|
51
|
+
|
|
52
|
+
/** Color to clear the canvas to before render, does not clear if alpha is 0
|
|
53
|
+
* @type {Color}
|
|
54
|
+
* @memberof Settings */
|
|
55
|
+
let canvasClearColor = CLEAR_BLACK;
|
|
56
|
+
|
|
57
|
+
/** The max size of the canvas in css pixels, centered if window is larger
|
|
58
|
+
* - Not affected by canvasPixelRatio, the backing store may be larger than this
|
|
59
|
+
* @type {Vector2}
|
|
60
|
+
* @default Vector2(3840,2160)
|
|
61
|
+
* @memberof Settings */
|
|
62
|
+
let canvasMaxSize = vec2(3840, 2160);
|
|
63
|
+
|
|
64
|
+
/** Minimum aspect ratio of the canvas (width/height), unused if 0
|
|
65
|
+
* Can be used with canvasMaxAspect to limit aspect ratio
|
|
66
|
+
* @type {number}
|
|
67
|
+
* @default
|
|
68
|
+
* @memberof Settings */
|
|
69
|
+
let canvasMinAspect = 0;
|
|
70
|
+
|
|
71
|
+
/** Maximum aspect ratio of the canvas (width/height), unused if 0
|
|
72
|
+
* Can be used with canvasMinAspect to limit aspect ratio
|
|
73
|
+
* @type {number}
|
|
74
|
+
* @default
|
|
75
|
+
* @memberof Settings */
|
|
76
|
+
let canvasMaxAspect = 0;
|
|
77
|
+
|
|
78
|
+
/** Fixed size of the canvas in css pixels, if enabled canvas size never changes
|
|
79
|
+
* - you may also need to set mainCanvasSize if using screen space coords in startup
|
|
80
|
+
* - canvasPixelRatio still applies, it only scales the backing store
|
|
81
|
+
* @type {Vector2}
|
|
82
|
+
* @default Vector2()
|
|
83
|
+
* @memberof Settings */
|
|
84
|
+
let canvasFixedSize = vec2();
|
|
85
|
+
|
|
86
|
+
/** Use nearest canvas scaling for more pixelated look
|
|
87
|
+
* - If enabled sets css image-rendering:pixelated
|
|
88
|
+
* @type {boolean}
|
|
89
|
+
* @default
|
|
90
|
+
* @memberof Settings */
|
|
91
|
+
let canvasPixelated = false;
|
|
92
|
+
|
|
93
|
+
/** Disables texture filtering for crisper pixel art
|
|
94
|
+
* - Leave true for pixel art so sprites stay sharp when scaled (uses NEAREST filtering)
|
|
95
|
+
* - Set false for smooth/high-resolution art to enable bilinear filtering and mipmaps
|
|
96
|
+
* @type {boolean}
|
|
97
|
+
* @default
|
|
98
|
+
* @memberof Settings */
|
|
99
|
+
let tilesPixelated = true;
|
|
100
|
+
|
|
101
|
+
/** Scale factor applied to the canvas resolution for sharper rendering
|
|
102
|
+
* Pass 1 for no scaling, a number for an explicit ratio, or undefined to track devicePixelRatio each frame.
|
|
103
|
+
* - Only the backing store scales, so this changes sharpness and nothing else
|
|
104
|
+
* - mainCanvasSize, cameraScale, mousePos and screen space stay in css pixels,
|
|
105
|
+
* so the same code draws the same size at any ratio
|
|
106
|
+
* - Pixel art usually looks best left at 1 or set to whole numbers,
|
|
107
|
+
* a fractional ratio samples texels unevenly
|
|
108
|
+
* @type {number|undefined}
|
|
109
|
+
* @default
|
|
110
|
+
* @memberof Settings */
|
|
111
|
+
let canvasPixelRatio = 1;
|
|
112
|
+
|
|
113
|
+
/** Default font used for text rendering
|
|
114
|
+
* @type {string}
|
|
115
|
+
* @default
|
|
116
|
+
* @memberof Settings */
|
|
117
|
+
let fontDefault = 'arial';
|
|
118
|
+
|
|
119
|
+
/** Enable to show the LittleJS splash screen on startup
|
|
120
|
+
* @type {boolean}
|
|
121
|
+
* @default
|
|
122
|
+
* @memberof Settings */
|
|
123
|
+
let showSplashScreen = false;
|
|
124
|
+
|
|
125
|
+
/** Disables all rendering, audio, and input for servers
|
|
126
|
+
* @type {boolean}
|
|
127
|
+
* @default
|
|
128
|
+
* @memberof Settings */
|
|
129
|
+
let headlessMode = false;
|
|
130
|
+
|
|
131
|
+
/** Disables the automatic requestAnimationFrame loop so the engine only
|
|
132
|
+
* advances when engineStep is called, for tests and frame-stepping tools
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
* @default
|
|
135
|
+
* @memberof Settings */
|
|
136
|
+
let engineManualStep = false;
|
|
137
|
+
|
|
138
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
139
|
+
// WebGL settings
|
|
140
|
+
|
|
141
|
+
/** Enable WebGL accelerated rendering
|
|
142
|
+
* @type {boolean}
|
|
143
|
+
* @default
|
|
144
|
+
* @memberof Settings */
|
|
145
|
+
let glEnable = true;
|
|
146
|
+
|
|
147
|
+
/** How many sided poly to use when drawing circles and ellipses with WebGL
|
|
148
|
+
* @type {number}
|
|
149
|
+
* @default
|
|
150
|
+
* @memberof Settings */
|
|
151
|
+
let glCircleSides = 32;
|
|
152
|
+
|
|
153
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
154
|
+
// Tile sheet settings
|
|
155
|
+
|
|
156
|
+
/** Default size of tiles in pixels
|
|
157
|
+
* @type {Vector2}
|
|
158
|
+
* @default Vector2(16,16)
|
|
159
|
+
* @memberof Settings */
|
|
160
|
+
let tileDefaultSize = vec2(16);
|
|
161
|
+
|
|
162
|
+
/** Default padding pixels around tiles
|
|
163
|
+
* @type {number}
|
|
164
|
+
* @default
|
|
165
|
+
* @memberof Settings */
|
|
166
|
+
let tileDefaultPadding = 0;
|
|
167
|
+
|
|
168
|
+
/** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
|
|
169
|
+
* @type {number}
|
|
170
|
+
* @default
|
|
171
|
+
* @memberof Settings */
|
|
172
|
+
let tileDefaultBleed = 0;
|
|
173
|
+
|
|
174
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
175
|
+
// Object settings
|
|
176
|
+
|
|
177
|
+
/** Enable physics solver for collisions between objects
|
|
178
|
+
* @type {boolean}
|
|
179
|
+
* @default
|
|
180
|
+
* @memberof Settings */
|
|
181
|
+
let enablePhysicsSolver = true;
|
|
182
|
+
|
|
183
|
+
/** Default object mass for collision calculations (how heavy objects are)
|
|
184
|
+
* @type {number}
|
|
185
|
+
* @default
|
|
186
|
+
* @memberof Settings */
|
|
187
|
+
let objectDefaultMass = 1;
|
|
188
|
+
|
|
189
|
+
/** How much to slow velocity by each frame (0-1)
|
|
190
|
+
* @type {number}
|
|
191
|
+
* @default
|
|
192
|
+
* @memberof Settings */
|
|
193
|
+
let objectDefaultDamping = 1;
|
|
194
|
+
|
|
195
|
+
/** How much to slow angular velocity each frame (0-1)
|
|
196
|
+
* @type {number}
|
|
197
|
+
* @default
|
|
198
|
+
* @memberof Settings */
|
|
199
|
+
let objectDefaultAngleDamping = 1;
|
|
200
|
+
|
|
201
|
+
/** How much to bounce when a collision occurs (0-1)
|
|
202
|
+
* @type {number}
|
|
203
|
+
* @default
|
|
204
|
+
* @memberof Settings */
|
|
205
|
+
let objectDefaultRestitution = 0;
|
|
206
|
+
|
|
207
|
+
/** How much to slow when touching (0-1)
|
|
208
|
+
* @type {number}
|
|
209
|
+
* @default
|
|
210
|
+
* @memberof Settings */
|
|
211
|
+
let objectDefaultFriction = .8;
|
|
212
|
+
|
|
213
|
+
/** Clamp max speed to avoid fast objects missing collisions
|
|
214
|
+
* @type {number}
|
|
215
|
+
* @default
|
|
216
|
+
* @memberof Settings */
|
|
217
|
+
let objectMaxSpeed = 1;
|
|
218
|
+
|
|
219
|
+
/** How much gravity to apply to objects, negative Y is down
|
|
220
|
+
* @type {Vector2}
|
|
221
|
+
* @default
|
|
222
|
+
* @memberof Settings */
|
|
223
|
+
let gravity = vec2();
|
|
224
|
+
|
|
225
|
+
/** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
|
|
226
|
+
* @type {number}
|
|
227
|
+
* @default
|
|
228
|
+
* @memberof Settings */
|
|
229
|
+
let particleEmitRateScale = 1;
|
|
230
|
+
|
|
231
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
232
|
+
// Input settings
|
|
233
|
+
|
|
234
|
+
/** Should gamepads be allowed
|
|
235
|
+
* @type {boolean}
|
|
236
|
+
* @default
|
|
237
|
+
* @memberof Settings */
|
|
238
|
+
let gamepadsEnable = true;
|
|
239
|
+
|
|
240
|
+
/** If true, the dpad input is also routed to the left analog stick (for better accessibility)
|
|
241
|
+
* @type {boolean}
|
|
242
|
+
* @default
|
|
243
|
+
* @memberof Settings */
|
|
244
|
+
let gamepadDirectionEmulateStick = true;
|
|
245
|
+
|
|
246
|
+
/** If true, axes that do not rest near center are ignored on gamepads without
|
|
247
|
+
* standard mapping. Steering wheels and flight sticks report pedal and throttle
|
|
248
|
+
* axes that rest at full deflection, which otherwise reads as a stick held down.
|
|
249
|
+
* @type {boolean}
|
|
250
|
+
* @default
|
|
251
|
+
* @memberof Settings */
|
|
252
|
+
let gamepadAxisFilterEnable = true;
|
|
253
|
+
|
|
254
|
+
/** If true the WASD keys are also routed to the direction keys (for better accessibility)
|
|
255
|
+
* @type {boolean}
|
|
256
|
+
* @default
|
|
257
|
+
* @memberof Settings */
|
|
258
|
+
let inputWASDEmulateDirection = true;
|
|
259
|
+
|
|
260
|
+
/** True if touch input is enabled for mobile devices
|
|
261
|
+
* - Touch events will be routed to mouse events
|
|
262
|
+
* @type {boolean}
|
|
263
|
+
* @default
|
|
264
|
+
* @memberof Settings */
|
|
265
|
+
let touchInputEnable = true;
|
|
266
|
+
|
|
267
|
+
/** True if touch gamepad should appear on mobile devices
|
|
268
|
+
* - Supports left analog stick, 4 face buttons and start button (button 9)
|
|
269
|
+
* - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
|
|
270
|
+
* - Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
|
|
271
|
+
* - Rendered as a full-viewport HTML/SVG overlay, so controls may sit outside the game canvas
|
|
272
|
+
* @type {boolean}
|
|
273
|
+
* @default
|
|
274
|
+
* @memberof Settings */
|
|
275
|
+
let touchGamepadEnable = false;
|
|
276
|
+
|
|
277
|
+
/** True if touches outside the gamepad controls should still drive mouse/touch input
|
|
278
|
+
* - When false (the default), enabling the touch gamepad suppresses touch-to-mouse input entirely
|
|
279
|
+
* - Set true to also pass touches outside the controls through to the game as mouse/touch input
|
|
280
|
+
* - Touches on the gamepad controls never drive the mouse regardless of this setting
|
|
281
|
+
* @type {boolean}
|
|
282
|
+
* @default
|
|
283
|
+
* @memberof Settings */
|
|
284
|
+
let touchGamepadPassthrough = false;
|
|
285
|
+
|
|
286
|
+
/** Size of center button if touch gamepad should have start button in the center
|
|
287
|
+
* - Prevents activating when pressed near virtual stick or face buttons
|
|
288
|
+
* - When the game is paused, any touch will press the button
|
|
289
|
+
* - Measured in viewport CSS pixels
|
|
290
|
+
* @type {number}
|
|
291
|
+
* @default
|
|
292
|
+
* @memberof Settings */
|
|
293
|
+
let touchGamepadCenterButtonSize = 0;
|
|
294
|
+
|
|
295
|
+
/** Number of buttons on the right side of the touch gamepad (0-4), using gamepad buttons 0-3
|
|
296
|
+
* - A count of 1 is a single large button (the size of a stick)
|
|
297
|
+
* - Ignored when touchGamepadRightStick is set (the right side is a stick instead)
|
|
298
|
+
* @type {number}
|
|
299
|
+
* @default
|
|
300
|
+
* @memberof Settings */
|
|
301
|
+
let touchGamepadButtonCount = 4;
|
|
302
|
+
|
|
303
|
+
/** True if the touch gamepad should have a left analog stick (or dpad)
|
|
304
|
+
* - When false, the left side is face buttons (touchGamepadLeftButtonCount) or nothing
|
|
305
|
+
* @type {boolean}
|
|
306
|
+
* @default
|
|
307
|
+
* @memberof Settings */
|
|
308
|
+
let touchGamepadLeftStick = true;
|
|
309
|
+
|
|
310
|
+
/** Number of buttons on the left side of the touch gamepad (0-4), using gamepad buttons 4-7
|
|
311
|
+
* - Only used when touchGamepadLeftStick is false (otherwise the left side is a stick)
|
|
312
|
+
* - A count of 1 is a single large button (the size of a stick)
|
|
313
|
+
* @type {number}
|
|
314
|
+
* @default
|
|
315
|
+
* @memberof Settings */
|
|
316
|
+
let touchGamepadLeftButtonCount = 0;
|
|
317
|
+
|
|
318
|
+
/** True if the touch gamepad right side should be an analog stick (or dpad) instead of face buttons
|
|
319
|
+
* - When set, touchGamepadButtonCount is ignored and the right side is a stick
|
|
320
|
+
* - Uses an analog stick when touchGamepadAnalog is true, otherwise an 8 way dpad
|
|
321
|
+
* @type {boolean}
|
|
322
|
+
* @default
|
|
323
|
+
* @memberof Settings */
|
|
324
|
+
let touchGamepadRightStick = false;
|
|
325
|
+
|
|
326
|
+
/** True if touch gamepad should be analog stick or false to use if 8 way dpad
|
|
327
|
+
* @type {boolean}
|
|
328
|
+
* @default
|
|
329
|
+
* @memberof Settings */
|
|
330
|
+
let touchGamepadAnalog = true;
|
|
331
|
+
|
|
332
|
+
/** True if touch gamepad directional controls should float to where you press
|
|
333
|
+
* - Only affects analog sticks and dpads, not face buttons
|
|
334
|
+
* - Directional controls re-anchor to where you press within the bottom ~60% of their screen half; the top ~40% passes through to the game
|
|
335
|
+
* - The right side floats only when it acts as the right analog stick (touchGamepadRightStick is set)
|
|
336
|
+
* - A center button (touchGamepadCenterButtonSize) still works since it ignores touches near the sticks
|
|
337
|
+
* @type {boolean}
|
|
338
|
+
* @default
|
|
339
|
+
* @memberof Settings */
|
|
340
|
+
let touchGamepadFloating = false;
|
|
341
|
+
|
|
342
|
+
/** Size of virtual gamepad for touch devices in viewport CSS pixels
|
|
343
|
+
* @type {number}
|
|
344
|
+
* @default
|
|
345
|
+
* @memberof Settings */
|
|
346
|
+
let touchGamepadSize = 100;
|
|
347
|
+
|
|
348
|
+
/** Transparency of touch gamepad overlay
|
|
349
|
+
* @type {number}
|
|
350
|
+
* @default
|
|
351
|
+
* @memberof Settings */
|
|
352
|
+
let touchGamepadAlpha = .3;
|
|
353
|
+
|
|
354
|
+
/** How long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
355
|
+
* @type {number}
|
|
356
|
+
* @default
|
|
357
|
+
* @memberof Settings */
|
|
358
|
+
let touchGamepadDisplayTime = 3;
|
|
359
|
+
|
|
360
|
+
/** Duration in ms to vibrate when a touch gamepad face button or start button is pressed
|
|
361
|
+
* - Set to 0 to disable, also requires vibrateEnable and hardware support (ignored on iOS)
|
|
362
|
+
* @type {number}
|
|
363
|
+
* @default
|
|
364
|
+
* @memberof Settings */
|
|
365
|
+
let touchGamepadVibration = 0;
|
|
366
|
+
|
|
367
|
+
/** Allow vibration hardware if it exists
|
|
368
|
+
* @type {boolean}
|
|
369
|
+
* @default
|
|
370
|
+
* @memberof Settings */
|
|
371
|
+
let vibrateEnable = true;
|
|
372
|
+
|
|
373
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
374
|
+
// Audio settings
|
|
375
|
+
|
|
376
|
+
/** All audio code can be disabled and removed from build
|
|
377
|
+
* @type {boolean}
|
|
378
|
+
* @default
|
|
379
|
+
* @memberof Settings */
|
|
380
|
+
let soundEnable = true;
|
|
381
|
+
|
|
382
|
+
/** Volume scale to apply to all sound, music and speech
|
|
383
|
+
* Use setSoundVolume to also update the audio master gain immediately
|
|
384
|
+
* @type {number}
|
|
385
|
+
* @default
|
|
386
|
+
* @memberof Settings */
|
|
387
|
+
let soundVolume = .3;
|
|
388
|
+
|
|
389
|
+
/** Default range where sound no longer plays
|
|
390
|
+
* @type {number}
|
|
391
|
+
* @default
|
|
392
|
+
* @memberof Settings */
|
|
393
|
+
let soundDefaultRange = 40;
|
|
394
|
+
|
|
395
|
+
/** Default range percent to start tapering off sound (0-1)
|
|
396
|
+
* @type {number}
|
|
397
|
+
* @default
|
|
398
|
+
* @memberof Settings */
|
|
399
|
+
let soundDefaultTaper = .7;
|
|
400
|
+
|
|
401
|
+
/** Pause all sound while the page is hidden, and pick up where it was when it shows again
|
|
402
|
+
* - A hidden page stops the game, so without this a looping sound plays on over a frozen game
|
|
403
|
+
* - Turn it off to keep music playing in a background tab
|
|
404
|
+
* @type {boolean}
|
|
405
|
+
* @default
|
|
406
|
+
* @memberof Settings */
|
|
407
|
+
let soundPauseWhenHidden = true;
|
|
408
|
+
|
|
409
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
410
|
+
// Setters for global variables
|
|
411
|
+
|
|
412
|
+
/** Set position of camera in world space
|
|
413
|
+
* @param {Vector2} pos
|
|
414
|
+
* @memberof Settings */
|
|
415
|
+
function setCameraPos(pos) { cameraPos = pos.copy(); }
|
|
416
|
+
|
|
417
|
+
/** Set angle of camera in world space
|
|
418
|
+
* @param {number} angle
|
|
419
|
+
* @memberof Settings */
|
|
420
|
+
function setCameraAngle(angle) { cameraAngle = angle; }
|
|
421
|
+
|
|
422
|
+
/** Set scale of camera in world space
|
|
423
|
+
* @param {number} scale
|
|
424
|
+
* @memberof Settings */
|
|
425
|
+
function setCameraScale(scale) { cameraScale = scale; }
|
|
426
|
+
|
|
427
|
+
/** Set scale applied to engine time
|
|
428
|
+
* @param {number} scale
|
|
429
|
+
* @memberof Settings */
|
|
430
|
+
function setTimeScale(scale) { timeScale = scale; }
|
|
431
|
+
|
|
432
|
+
/** Set if tiles should be colorized when using canvas2d
|
|
433
|
+
* This can be slower but results should look nearly identical to WebGL rendering
|
|
434
|
+
* It can be enabled/disabled at any time
|
|
435
|
+
* Optimized for performance, and will use faster method if color is white or untextured
|
|
436
|
+
* @param {boolean} colorTiles
|
|
437
|
+
* @memberof Settings */
|
|
438
|
+
function setCanvasColorTiles(colorTiles) { canvasColorTiles = colorTiles; }
|
|
439
|
+
|
|
440
|
+
/** Set color to clear the canvas to before render, does not clear if alpha is 0
|
|
441
|
+
* @param {Color} color
|
|
442
|
+
* @memberof Settings */
|
|
443
|
+
function setCanvasClearColor(color) { canvasClearColor = color.copy(); }
|
|
444
|
+
|
|
445
|
+
/** Set max size of the canvas
|
|
446
|
+
* @param {Vector2} size
|
|
447
|
+
* @memberof Settings */
|
|
448
|
+
function setCanvasMaxSize(size) { canvasMaxSize = size.copy(); }
|
|
449
|
+
|
|
450
|
+
/** Set minimum aspect ratio of the canvas (width/height), unused if 0
|
|
451
|
+
* @param {number} aspect
|
|
452
|
+
* @memberof Settings */
|
|
453
|
+
function setCanvasMinAspect(aspect) { canvasMinAspect = aspect; }
|
|
454
|
+
|
|
455
|
+
/** Set maximum aspect ratio of the canvas (width/height), unused if 0
|
|
456
|
+
* @param {number} aspect
|
|
457
|
+
* @memberof Settings */
|
|
458
|
+
function setCanvasMaxAspect(aspect) { canvasMaxAspect = aspect; }
|
|
459
|
+
|
|
460
|
+
/** Set fixed size of the canvas
|
|
461
|
+
* @param {Vector2} size
|
|
462
|
+
* @memberof Settings */
|
|
463
|
+
function setCanvasFixedSize(size) { canvasFixedSize = size.copy(); }
|
|
464
|
+
|
|
465
|
+
/** Use nearest scaling algorithm for canvas for more pixelated look
|
|
466
|
+
* @param {boolean} pixelated
|
|
467
|
+
* @memberof Settings */
|
|
468
|
+
function setCanvasPixelated(pixelated)
|
|
469
|
+
{
|
|
470
|
+
canvasPixelated = pixelated;
|
|
471
|
+
if (mainCanvas)
|
|
472
|
+
mainCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
|
|
473
|
+
if (glCanvas)
|
|
474
|
+
glCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** Disables texture filtering for crisper pixel art
|
|
478
|
+
* - Leave true for pixel art; set false for smooth/high-resolution art
|
|
479
|
+
* @param {boolean} pixelated
|
|
480
|
+
* @memberof Settings */
|
|
481
|
+
function setTilesPixelated(pixelated) { tilesPixelated = pixelated; }
|
|
482
|
+
|
|
483
|
+
/** Set the canvas pixel ratio, scales the render resolution for sharper output
|
|
484
|
+
* Pass a number for an explicit ratio, or call with no argument to track devicePixelRatio each frame.
|
|
485
|
+
* - The canvas stays the same size on screen and everything draws the same
|
|
486
|
+
* size, it just renders at a higher resolution so nothing looks blurry
|
|
487
|
+
* - Game code is unaffected, it always works in css pixels
|
|
488
|
+
* @param {number} [pixelRatio]
|
|
489
|
+
* @example
|
|
490
|
+
* // render at native resolution, capped so phones don't pay for 3x
|
|
491
|
+
* setCanvasPixelRatio(min(devicePixelRatio, 2));
|
|
492
|
+
* @memberof Settings */
|
|
493
|
+
function setCanvasPixelRatio(pixelRatio) { canvasPixelRatio = pixelRatio; }
|
|
494
|
+
|
|
495
|
+
/** Get the pixel ratio currently applied to the canvas backing store
|
|
496
|
+
* - Resolves canvasPixelRatio, falling back to devicePixelRatio when it is undefined
|
|
497
|
+
* - Game code works in css pixels so this is rarely needed, it is for sizing
|
|
498
|
+
* render targets and viewports that must match the backing store
|
|
499
|
+
* @return {number}
|
|
500
|
+
* @memberof Settings */
|
|
501
|
+
function getCanvasPixelRatio() { return canvasPixelRatio ?? (devicePixelRatio || 1); }
|
|
502
|
+
|
|
503
|
+
/** Set default font used for text rendering
|
|
504
|
+
* @param {string} font
|
|
505
|
+
* @memberof Settings */
|
|
506
|
+
function setFontDefault(font) { fontDefault = font; }
|
|
507
|
+
|
|
508
|
+
/** Set if the LittleJS splash screen should be shown on startup
|
|
509
|
+
* @param {boolean} show
|
|
510
|
+
* @memberof Settings */
|
|
511
|
+
function setShowSplashScreen(show) { showSplashScreen = show; }
|
|
512
|
+
|
|
513
|
+
/** Set to disable rendering, audio, and input for servers
|
|
514
|
+
* @param {boolean} headless
|
|
515
|
+
* @memberof Settings */
|
|
516
|
+
function setHeadlessMode(headless) { headlessMode = headless; }
|
|
517
|
+
|
|
518
|
+
/** Set if the engine only advances when engineStep is called
|
|
519
|
+
* Must be set before engineInit
|
|
520
|
+
* @param {boolean} [enable]
|
|
521
|
+
* @memberof Settings */
|
|
522
|
+
function setEngineManualStep(enable=true) { engineManualStep = enable; }
|
|
523
|
+
|
|
524
|
+
/** Set if WebGL rendering is enabled
|
|
525
|
+
* @param {boolean} enable
|
|
526
|
+
* @memberof Settings */
|
|
527
|
+
function setGLEnable(enable)
|
|
528
|
+
{
|
|
529
|
+
if (enable && !glCanBeEnabled)
|
|
530
|
+
{
|
|
531
|
+
console.warn('Can not enable WebGL if it was disabled on start.');
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
glEnable = enable;
|
|
535
|
+
if (glCanvas) // hide glCanvas if WebGL is disabled
|
|
536
|
+
glCanvas.style.display = enable ? '' : 'none';
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/** Set how many sided polygons to use when drawing circles and ellipses with WebGL
|
|
540
|
+
* @param {number} sides
|
|
541
|
+
* @memberof Settings */
|
|
542
|
+
function setGLCircleSides(sides) { glCircleSides = sides; }
|
|
543
|
+
|
|
544
|
+
/** Set default size of tiles in pixels
|
|
545
|
+
* @param {Vector2} size
|
|
546
|
+
* @memberof Settings */
|
|
547
|
+
function setTileDefaultSize(size) { tileDefaultSize = size.copy(); }
|
|
548
|
+
|
|
549
|
+
/** Default padding pixels around tiles
|
|
550
|
+
* @param {number} padding
|
|
551
|
+
* @memberof Settings */
|
|
552
|
+
function setTileDefaultPadding(padding) { tileDefaultPadding = padding; }
|
|
553
|
+
|
|
554
|
+
/** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
|
|
555
|
+
* @param {number} bleed
|
|
556
|
+
* @memberof Settings */
|
|
557
|
+
function setTileDefaultBleed(bleed) { tileDefaultBleed = bleed; }
|
|
558
|
+
|
|
559
|
+
/** Set if collisions between objects are enabled
|
|
560
|
+
* @param {boolean} enable
|
|
561
|
+
* @memberof Settings */
|
|
562
|
+
function setEnablePhysicsSolver(enable) { enablePhysicsSolver = enable; }
|
|
563
|
+
|
|
564
|
+
/** Set default object mass for collision calculations
|
|
565
|
+
* @param {number} mass
|
|
566
|
+
* @memberof Settings */
|
|
567
|
+
function setObjectDefaultMass(mass) { objectDefaultMass = mass; }
|
|
568
|
+
|
|
569
|
+
/** Set how much to slow velocity by each frame
|
|
570
|
+
* @param {number} damp
|
|
571
|
+
* @memberof Settings */
|
|
572
|
+
function setObjectDefaultDamping(damp) { objectDefaultDamping = damp; }
|
|
573
|
+
|
|
574
|
+
/** Set how much to slow angular velocity each frame
|
|
575
|
+
* @param {number} damp
|
|
576
|
+
* @memberof Settings */
|
|
577
|
+
function setObjectDefaultAngleDamping(damp) { objectDefaultAngleDamping = damp; }
|
|
578
|
+
|
|
579
|
+
/** Set how much to bounce when a collision occurs
|
|
580
|
+
* @param {number} restitution
|
|
581
|
+
* @memberof Settings */
|
|
582
|
+
function setObjectDefaultRestitution(restitution) { objectDefaultRestitution = restitution; }
|
|
583
|
+
|
|
584
|
+
/** Set how much to slow when touching
|
|
585
|
+
* @param {number} friction
|
|
586
|
+
* @memberof Settings */
|
|
587
|
+
function setObjectDefaultFriction(friction) { objectDefaultFriction = friction; }
|
|
588
|
+
|
|
589
|
+
/** Set max speed to avoid fast objects missing collisions
|
|
590
|
+
* @param {number} speed
|
|
591
|
+
* @memberof Settings */
|
|
592
|
+
function setObjectMaxSpeed(speed) { objectMaxSpeed = speed; }
|
|
593
|
+
|
|
594
|
+
/** Set how much gravity to apply to objects
|
|
595
|
+
* @param {Vector2} newGravity
|
|
596
|
+
* @memberof Settings */
|
|
597
|
+
function setGravity(newGravity) { gravity = newGravity.copy(); }
|
|
598
|
+
|
|
599
|
+
/** Set to scales emit rate of particles
|
|
600
|
+
* @param {number} scale
|
|
601
|
+
* @memberof Settings */
|
|
602
|
+
function setParticleEmitRateScale(scale) { particleEmitRateScale = scale; }
|
|
603
|
+
|
|
604
|
+
/** Set if gamepads are enabled
|
|
605
|
+
* @param {boolean} enable
|
|
606
|
+
* @memberof Settings */
|
|
607
|
+
function setGamepadsEnable(enable) { gamepadsEnable = enable; }
|
|
608
|
+
|
|
609
|
+
/** Set if the dpad input is also routed to the left analog stick
|
|
610
|
+
* @param {boolean} enable
|
|
611
|
+
* @memberof Settings */
|
|
612
|
+
function setGamepadDirectionEmulateStick(enable) { gamepadDirectionEmulateStick = enable; }
|
|
613
|
+
|
|
614
|
+
/** Set if axes that do not rest near center are ignored on non-standard gamepads
|
|
615
|
+
* @param {boolean} enable
|
|
616
|
+
* @memberof Settings */
|
|
617
|
+
function setGamepadAxisFilterEnable(enable) { gamepadAxisFilterEnable = enable; }
|
|
618
|
+
|
|
619
|
+
/** Set if true the WASD keys are also routed to the direction keys
|
|
620
|
+
* @param {boolean} enable
|
|
621
|
+
* @memberof Settings */
|
|
622
|
+
function setInputWASDEmulateDirection(enable) { inputWASDEmulateDirection = enable; }
|
|
623
|
+
|
|
624
|
+
/** Set if touch input is allowed
|
|
625
|
+
* @param {boolean} enable
|
|
626
|
+
* @memberof Settings */
|
|
627
|
+
function setTouchInputEnable(enable) { touchInputEnable = enable; }
|
|
628
|
+
|
|
629
|
+
/** Set if touch gamepad should appear on mobile devices
|
|
630
|
+
* @param {boolean} enable
|
|
631
|
+
* @memberof Settings */
|
|
632
|
+
function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
|
|
633
|
+
|
|
634
|
+
/** Set if touches outside the gamepad controls should still drive mouse/touch input
|
|
635
|
+
* @param {boolean} passthrough
|
|
636
|
+
* @memberof Settings */
|
|
637
|
+
function setTouchGamepadPassthrough(passthrough) { touchGamepadPassthrough = passthrough; }
|
|
638
|
+
|
|
639
|
+
/** Set if touch gamepad should have start button in the center
|
|
640
|
+
* - Set size to enable the center button
|
|
641
|
+
* - When the game is paused, any touch will press the button
|
|
642
|
+
* @param {number} size
|
|
643
|
+
* @memberof Settings */
|
|
644
|
+
function setTouchGamepadCenterButtonSize(size) { touchGamepadCenterButtonSize = size; }
|
|
645
|
+
|
|
646
|
+
/** Set number of buttons on the right side of the touch gamepad (0-4, gamepad buttons 0-3)
|
|
647
|
+
* @param {number} count
|
|
648
|
+
* @memberof Settings */
|
|
649
|
+
function setTouchGamepadButtonCount(count)
|
|
650
|
+
{
|
|
651
|
+
touchGamepadButtonCount = count;
|
|
652
|
+
if (count > 0)
|
|
653
|
+
touchGamepadRightStick = false;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Set if the touch gamepad should have a left analog stick (or dpad)
|
|
657
|
+
* @param {boolean} enable
|
|
658
|
+
* @memberof Settings */
|
|
659
|
+
function setTouchGamepadLeftStick(enable)
|
|
660
|
+
{
|
|
661
|
+
touchGamepadLeftStick = enable;
|
|
662
|
+
if (enable)
|
|
663
|
+
touchGamepadLeftButtonCount = 0;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** Set number of buttons on the left side of the touch gamepad (0-4, gamepad buttons 4-7)
|
|
667
|
+
* - Only used when touchGamepadLeftStick is false
|
|
668
|
+
* @param {number} count
|
|
669
|
+
* @memberof Settings */
|
|
670
|
+
function setTouchGamepadLeftButtonCount(count)
|
|
671
|
+
{
|
|
672
|
+
touchGamepadLeftButtonCount = count;
|
|
673
|
+
if (count > 0)
|
|
674
|
+
touchGamepadLeftStick = false;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/** Set if the touch gamepad right side is an analog stick (or dpad) instead of face buttons
|
|
678
|
+
* @param {boolean} rightStick
|
|
679
|
+
* @memberof Settings */
|
|
680
|
+
function setTouchGamepadRightStick(rightStick)
|
|
681
|
+
{
|
|
682
|
+
touchGamepadRightStick = rightStick;
|
|
683
|
+
if (rightStick)
|
|
684
|
+
touchGamepadButtonCount = 0;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** Set if touch gamepad should be analog stick or 8 way dpad
|
|
688
|
+
* @param {boolean} analog
|
|
689
|
+
* @memberof Settings */
|
|
690
|
+
function setTouchGamepadAnalog(analog) { touchGamepadAnalog = analog; }
|
|
691
|
+
|
|
692
|
+
/** Set if touch gamepad directional controls should float to where you press
|
|
693
|
+
* @param {boolean} floating
|
|
694
|
+
* @memberof Settings */
|
|
695
|
+
function setTouchGamepadFloating(floating) { touchGamepadFloating = floating; }
|
|
696
|
+
|
|
697
|
+
/** Set size of virtual gamepad for touch devices in pixels
|
|
698
|
+
* @param {number} size
|
|
699
|
+
* @memberof Settings */
|
|
700
|
+
function setTouchGamepadSize(size) { touchGamepadSize = size; }
|
|
701
|
+
|
|
702
|
+
/** Set transparency of touch gamepad overlay
|
|
703
|
+
* @param {number} alpha
|
|
704
|
+
* @memberof Settings */
|
|
705
|
+
function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
|
|
706
|
+
|
|
707
|
+
/** Set how long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
708
|
+
* @param {number} time
|
|
709
|
+
* @memberof Settings */
|
|
710
|
+
function setTouchGamepadDisplayTime(time) { touchGamepadDisplayTime = time; }
|
|
711
|
+
|
|
712
|
+
/** Set duration in ms to vibrate when a touch gamepad face or start button is pressed (0 disables)
|
|
713
|
+
* @param {number} ms
|
|
714
|
+
* @memberof Settings */
|
|
715
|
+
function setTouchGamepadVibration(ms) { touchGamepadVibration = ms; }
|
|
716
|
+
|
|
717
|
+
/** Set to allow vibration hardware if it exists
|
|
718
|
+
* @param {boolean} enable
|
|
719
|
+
* @memberof Settings */
|
|
720
|
+
function setVibrateEnable(enable) { vibrateEnable = enable; }
|
|
721
|
+
|
|
722
|
+
/** Set to disable all audio code
|
|
723
|
+
* @param {boolean} enable
|
|
724
|
+
* @memberof Settings */
|
|
725
|
+
function setSoundEnable(enable) { soundEnable = enable; }
|
|
726
|
+
|
|
727
|
+
/** Set volume scale to apply to all sound, music and speech
|
|
728
|
+
* @param {number} volume
|
|
729
|
+
* @memberof Settings */
|
|
730
|
+
function setSoundVolume(volume)
|
|
731
|
+
{
|
|
732
|
+
soundVolume = volume;
|
|
733
|
+
if (soundEnable && !headlessMode && audioMasterGain)
|
|
734
|
+
audioMasterGain.gain.value = volume; // update gain immediately
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** Set default range where sound no longer plays
|
|
738
|
+
* @param {number} range
|
|
739
|
+
* @memberof Settings */
|
|
740
|
+
function setSoundDefaultRange(range) { soundDefaultRange = range; }
|
|
741
|
+
|
|
742
|
+
/** Set default range percent to start tapering off sound
|
|
743
|
+
* @param {number} taper
|
|
744
|
+
* @memberof Settings */
|
|
745
|
+
function setSoundDefaultTaper(taper) { soundDefaultTaper = taper; }
|
|
746
|
+
|
|
747
|
+
/** Set if all sound pauses while the page is hidden
|
|
748
|
+
* @param {boolean} pause
|
|
749
|
+
* @memberof Settings */
|
|
750
|
+
function setSoundPauseWhenHidden(pause) { soundPauseWhenHidden = pause; }
|
|
751
|
+
|
|
752
|
+
/** Set if watermark with FPS should be shown
|
|
753
|
+
* @param {boolean} show
|
|
754
|
+
* @memberof Debug */
|
|
755
|
+
function setDebugWatermark(show) { debugWatermark = show; }
|
|
756
|
+
|
|
757
|
+
/** Set key code used to toggle debug mode, Esc by default
|
|
758
|
+
* @param {string} key
|
|
759
|
+
* @memberof Debug */
|
|
726
760
|
function setDebugKey(key) { debugKey = key; }
|