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