littlejsengine 1.8.1 → 1.8.4

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,2003 +0,0 @@
1
- declare module "littlejs.esm" {
2
- /** Set position of camera in world space
3
- * @param {Vector2} pos
4
- * @memberof Settings */
5
- export function setCameraPos(pos: Vector2): void;
6
- /** Set scale of camera in world space
7
- * @param {Number} scale
8
- * @memberof Settings */
9
- export function setCameraScale(scale: number): void;
10
- /** Set max size of the canvas
11
- * @param {Vector2} size
12
- * @memberof Settings */
13
- export function setCanvasMaxSize(size: Vector2): void;
14
- /** Set fixed size of the canvas
15
- * @param {Vector2} size
16
- * @memberof Settings */
17
- export function setCanvasFixedSize(size: Vector2): void;
18
- /** Disables anti aliasing for pixel art if true
19
- * @param {Boolean} pixelated
20
- * @memberof Settings */
21
- export function setCanvasPixelated(pixelated: boolean): void;
22
- /** Set default font used for text rendering
23
- * @param {String} font
24
- * @memberof Settings */
25
- export function setFontDefault(font: string): void;
26
- /** Set if webgl rendering is enabled
27
- * @param {Boolean} enable
28
- * @memberof Settings */
29
- export function setGlEnable(enable: boolean): void;
30
- /** Set to not composite the WebGL canvas
31
- * @param {Boolean} overlay
32
- * @memberof Settings */
33
- export function setGlOverlay(overlay: boolean): void;
34
- /** Set default size of tiles in pixels
35
- * @param {Vector2} size
36
- * @memberof Settings */
37
- export function setTileSizeDefault(size: Vector2): void;
38
- /** Set to prevent tile bleeding from neighbors in pixels
39
- * @param {Number} scale
40
- * @memberof Settings */
41
- export function setTileFixBleedScale(scale: number): void;
42
- /** Set if collisions between objects are enabled
43
- * @param {Boolean} enable
44
- * @memberof Settings */
45
- export function setEnablePhysicsSolver(enable: boolean): void;
46
- /** Set default object mass for collison calcuations
47
- * @param {Number} mass
48
- * @memberof Settings */
49
- export function setObjectDefaultMass(mass: number): void;
50
- /** Set how much to slow velocity by each frame
51
- * @param {Number} damping
52
- * @memberof Settings */
53
- export function setObjectDefaultDamping(damp: any): void;
54
- /** Set how much to slow angular velocity each frame
55
- * @param {Number} damping
56
- * @memberof Settings */
57
- export function setObjectDefaultAngleDamping(damp: any): void;
58
- /** Set how much to bounce when a collision occur
59
- * @param {Number} elasticity
60
- * @memberof Settings */
61
- export function setObjectDefaultElasticity(elasticity: number): void;
62
- /** Set how much to slow when touching
63
- * @param {Number} friction
64
- * @memberof Settings */
65
- export function setObjectDefaultFriction(friction: number): void;
66
- /** Set max speed to avoid fast objects missing collisions
67
- * @param {Number} speed
68
- * @memberof Settings */
69
- export function setObjectMaxSpeed(speed: number): void;
70
- /** Set how much gravity to apply to objects along the Y axis
71
- * @param {Number} gravity
72
- * @memberof Settings */
73
- export function setGravity(g: any): void;
74
- /** Set to scales emit rate of particles
75
- * @param {Number} scale
76
- * @memberof Settings */
77
- export function setParticleEmitRateScale(scale: number): void;
78
- /** Set if gamepads are enabled
79
- * @param {Boolean} enable
80
- * @memberof Settings */
81
- export function setGamepadsEnable(enable: boolean): void;
82
- /** Set if the dpad input is also routed to the left analog stick
83
- * @param {Boolean} enable
84
- * @memberof Settings */
85
- export function setGamepadDirectionEmulateStick(enable: boolean): void;
86
- /** Set if true the WASD keys are also routed to the direction keys
87
- * @param {Boolean} enable
88
- * @memberof Settings */
89
- export function setInputWASDEmulateDirection(enable: boolean): void;
90
- /** Set if touch gamepad should appear on mobile devices
91
- * @param {Boolean} enable
92
- * @memberof Settings */
93
- export function setTouchGamepadEnable(enable: boolean): void;
94
- /** Set if touch gamepad should be analog stick or 8 way dpad
95
- * @param {Boolean} analog
96
- * @memberof Settings */
97
- export function setTouchGamepadAnalog(analog: boolean): void;
98
- /** Set size of virutal gamepad for touch devices in pixels
99
- * @param {Number} size
100
- * @memberof Settings */
101
- export function setTouchGamepadSize(size: number): void;
102
- /** Set transparency of touch gamepad overlay
103
- * @param {Number} alpha
104
- * @memberof Settings */
105
- export function setTouchGamepadAlpha(alpha: number): void;
106
- /** Set to allow vibration hardware if it exists
107
- * @param {Boolean} enable
108
- * @memberof Settings */
109
- export function setVibrateEnable(enable: boolean): void;
110
- /** Set to disable all audio code
111
- * @param {Boolean} enable
112
- * @memberof Settings */
113
- export function setSoundEnable(enable: boolean): void;
114
- /** Set volume scale to apply to all sound, music and speech
115
- * @param {Number} volume
116
- * @memberof Settings */
117
- export function setSoundVolume(volume: number): void;
118
- /** Set default range where sound no longer plays
119
- * @param {Number} range
120
- * @memberof Settings */
121
- export function setSoundDefaultRange(range: number): void;
122
- /** Set default range percent to start tapering off sound
123
- * @param {Number} taper
124
- * @memberof Settings */
125
- export function setSoundDefaultTaper(taper: number): void;
126
- /** Set how long to show medals for in seconds
127
- * @param {Number} time
128
- * @memberof Settings */
129
- export function setMedalDisplayTime(time: number): void;
130
- /** Set how quickly to slide on/off medals in seconds
131
- * @param {Number} time
132
- * @memberof Settings */
133
- export function setMedalDisplaySlideTime(time: number): void;
134
- /** Set size of medal display
135
- * @param {Vector2} size
136
- * @memberof Settings */
137
- export function setMedalDisplaySize(size: Vector2): void;
138
- /** Set size of icon in medal display
139
- * @param {Number} size
140
- * @memberof Settings */
141
- export function setMedalDisplayIconSize(size: number): void;
142
- /** Set to stop medals from being unlockable
143
- * @param {Boolean} preventUnlock
144
- * @memberof Settings */
145
- export function setMedalsPreventUnlock(preventUnlock: boolean): void;
146
- /** Set if watermark with FPS should be shown
147
- * @param {Boolean} show
148
- * @memberof Debug */
149
- export function setShowWatermark(show: boolean): void;
150
- /** Set key code used to toggle debug mode, Esc by default
151
- * @param {Number} key
152
- * @memberof Debug */
153
- export function setDebugKey(key: number): void;
154
- /** The max size of the canvas, centered if window is larger
155
- * @type {Vector2}
156
- * @default Vector2(1920,1200)
157
- * @memberof Settings */
158
- export let canvasMaxSize: Vector2;
159
- /** Fixed size of the canvas, if enabled canvas size never changes
160
- * - you may also need to set mainCanvasSize if using screen space coords in startup
161
- * @type {Vector2}
162
- * @default Vector2()
163
- * @memberof Settings */
164
- export let canvasFixedSize: Vector2;
165
- /** Disables filtering for crisper pixel art if true
166
- * @type {Boolean}
167
- * @default
168
- * @memberof Settings */
169
- export let canvasPixelated: boolean;
170
- /** Default font used for text rendering
171
- * @type {String}
172
- * @default
173
- * @memberof Settings */
174
- export let fontDefault: string;
175
- /** Default size of tiles in pixels
176
- * @type {Vector2}
177
- * @default Vector2(16,16)
178
- * @memberof Settings */
179
- export let tileSizeDefault: Vector2;
180
- /** How many pixels smaller to draw tiles to prevent bleeding from neighbors
181
- * @type {Number}
182
- * @default
183
- * @memberof Settings */
184
- export let tileFixBleedScale: number;
185
- /** Enable physics solver for collisions between objects
186
- * @type {Boolean}
187
- * @default
188
- * @memberof Settings */
189
- export let enablePhysicsSolver: boolean;
190
- /** Default object mass for collison calcuations (how heavy objects are)
191
- * @type {Number}
192
- * @default
193
- * @memberof Settings */
194
- export let objectDefaultMass: number;
195
- /** How much to slow velocity by each frame (0-1)
196
- * @type {Number}
197
- * @default
198
- * @memberof Settings */
199
- export let objectDefaultDamping: number;
200
- /** How much to slow angular velocity each frame (0-1)
201
- * @type {Number}
202
- * @default
203
- * @memberof Settings */
204
- export let objectDefaultAngleDamping: number;
205
- /** How much to bounce when a collision occurs (0-1)
206
- * @type {Number}
207
- * @default 0
208
- * @memberof Settings */
209
- export let objectDefaultElasticity: number;
210
- /** How much to slow when touching (0-1)
211
- * @type {Number}
212
- * @default
213
- * @memberof Settings */
214
- export let objectDefaultFriction: number;
215
- /** Clamp max speed to avoid fast objects missing collisions
216
- * @type {Number}
217
- * @default
218
- * @memberof Settings */
219
- export let objectMaxSpeed: number;
220
- /** How much gravity to apply to objects along the Y axis, negative is down
221
- * @type {Number}
222
- * @default 0
223
- * @memberof Settings */
224
- export let gravity: number;
225
- /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
226
- * @type {Number}
227
- * @default
228
- * @memberof Settings */
229
- export let particleEmitRateScale: number;
230
- /**
231
- * LittleJS Engine Settings
232
- * - All settings for the engine are here
233
- * @namespace Settings
234
- */
235
- /** Position of camera in world space
236
- * @type {Vector2}
237
- * @default Vector2()
238
- * @memberof Settings */
239
- export let cameraPos: Vector2;
240
- /** Scale of camera in world space
241
- * @type {Number}
242
- * @default
243
- * @memberof Settings */
244
- export let cameraScale: number;
245
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
246
- * @type {Boolean}
247
- * @default
248
- * @memberof Settings */
249
- export let glEnable: boolean;
250
- /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
251
- * @type {Boolean}
252
- * @default
253
- * @memberof Settings */
254
- export let glOverlay: boolean;
255
- /** Should gamepads be allowed
256
- * @type {Boolean}
257
- * @default
258
- * @memberof Settings */
259
- export let gamepadsEnable: boolean;
260
- /** If true, the dpad input is also routed to the left analog stick (for better accessability)
261
- * @type {Boolean}
262
- * @default
263
- * @memberof Settings */
264
- export let gamepadDirectionEmulateStick: boolean;
265
- /** If true the WASD keys are also routed to the direction keys (for better accessability)
266
- * @type {Boolean}
267
- * @default
268
- * @memberof Settings */
269
- export let inputWASDEmulateDirection: boolean;
270
- /** True if touch gamepad should appear on mobile devices
271
- * - Supports left analog stick, 4 face buttons and start button (button 9)
272
- * - Must be set by end of gameInit to be activated
273
- * @type {Boolean}
274
- * @default 0
275
- * @memberof Settings */
276
- export let touchGamepadEnable: boolean;
277
- /** True if touch gamepad should be analog stick or false to use if 8 way dpad
278
- * @type {Boolean}
279
- * @default
280
- * @memberof Settings */
281
- export let touchGamepadAnalog: boolean;
282
- /** Size of virutal gamepad for touch devices in pixels
283
- * @type {Number}
284
- * @default
285
- * @memberof Settings */
286
- export let touchGamepadSize: number;
287
- /** Transparency of touch gamepad overlay
288
- * @type {Number}
289
- * @default
290
- * @memberof Settings */
291
- export let touchGamepadAlpha: number;
292
- /** Allow vibration hardware if it exists
293
- * @type {Boolean}
294
- * @default
295
- * @memberof Settings */
296
- export let vibrateEnable: boolean;
297
- /** All audio code can be disabled and removed from build
298
- * @type {Boolean}
299
- * @default
300
- * @memberof Settings */
301
- export let soundEnable: boolean;
302
- /** Volume scale to apply to all sound, music and speech
303
- * @type {Number}
304
- * @default
305
- * @memberof Settings */
306
- export let soundVolume: number;
307
- /** Default range where sound no longer plays
308
- * @type {Number}
309
- * @default
310
- * @memberof Settings */
311
- export let soundDefaultRange: number;
312
- /** Default range percent to start tapering off sound (0-1)
313
- * @type {Number}
314
- * @default
315
- * @memberof Settings */
316
- export let soundDefaultTaper: number;
317
- /** How long to show medals for in seconds
318
- * @type {Number}
319
- * @default
320
- * @memberof Settings */
321
- export let medalDisplayTime: number;
322
- /** How quickly to slide on/off medals in seconds
323
- * @type {Number}
324
- * @default
325
- * @memberof Settings */
326
- export let medalDisplaySlideTime: number;
327
- /** Size of medal display
328
- * @type {Vector2}
329
- * @default Vector2(640,80)
330
- * @memberof Settings */
331
- export let medalDisplaySize: Vector2;
332
- /** Size of icon in medal display
333
- * @type {Number}
334
- * @default
335
- * @memberof Settings */
336
- export let medalDisplayIconSize: number;
337
- /**
338
- * LittleJS Debug System
339
- * - Press Esc to show debug overlay with mouse pick
340
- * - Number keys toggle debug functions
341
- * - +/- apply time scale
342
- * - Debug primitive rendering
343
- * - Save a 2d canvas as a png image
344
- * @namespace Debug
345
- */
346
- /** True if debug is enabled
347
- * @type {Boolean}
348
- * @default
349
- * @memberof Debug */
350
- export const debug: boolean;
351
- /** True if watermark with FPS should be shown, false in release builds
352
- * @type {Boolean}
353
- * @default
354
- * @memberof Debug */
355
- export let showWatermark: boolean;
356
- /** Asserts if the experssion is false, does not do anything in release builds
357
- * @param {Boolean} assertion
358
- * @param {Object} output
359
- * @memberof Debug */
360
- export function ASSERT(...assert: any[]): void;
361
- /** Draw a debug rectangle in world space
362
- * @param {Vector2} pos
363
- * @param {Vector2} [size=Vector2()]
364
- * @param {String} [color='#fff']
365
- * @param {Number} [time=0]
366
- * @param {Number} [angle=0]
367
- * @param {Boolean} [fill=false]
368
- * @memberof Debug */
369
- export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
370
- /** Draw a debug circle in world space
371
- * @param {Vector2} pos
372
- * @param {Number} [radius=0]
373
- * @param {String} [color='#fff']
374
- * @param {Number} [time=0]
375
- * @param {Boolean} [fill=false]
376
- * @memberof Debug */
377
- export function debugCircle(pos: Vector2, radius?: number, color?: string, time?: number, fill?: boolean): void;
378
- /** Draw a debug point in world space
379
- * @param {Vector2} pos
380
- * @param {String} [color='#fff']
381
- * @param {Number} [time=0]
382
- * @param {Number} [angle=0]
383
- * @memberof Debug */
384
- export function debugPoint(pos: Vector2, color?: string, time?: number, angle?: number): void;
385
- /** Draw a debug line in world space
386
- * @param {Vector2} posA
387
- * @param {Vector2} posB
388
- * @param {String} [color='#fff']
389
- * @param {Number} [thickness=.1]
390
- * @param {Number} [time=0]
391
- * @memberof Debug */
392
- export function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
393
- /** Draw a debug axis aligned bounding box in world space
394
- * @param {Vector2} posA
395
- * @param {Vector2} sizeA
396
- * @param {Vector2} posB
397
- * @param {Vector2} sizeB
398
- * @param {String} [color='#fff']
399
- * @memberof Debug */
400
- export function debugAABB(pA: any, sA: any, pB: any, sB: any, color?: string): void;
401
- /** Draw a debug axis aligned bounding box in world space
402
- * @param {String} text
403
- * @param {Vector2} pos
404
- * @param {Number} [size=1]
405
- * @param {String} [color='#fff']
406
- * @param {Number} [time=0]
407
- * @param {Number} [angle=0]
408
- * @param {String} [font='monospace']
409
- * @memberof Debug */
410
- export function debugText(text: string, pos: Vector2, size?: number, color?: string, time?: number, angle?: number, font?: string): void;
411
- /** Clear all debug primitives in the list
412
- * @memberof Debug */
413
- export function debugClear(): void;
414
- /** Save a canvas to disk
415
- * @param {HTMLCanvasElement} canvas
416
- * @param {String} [filename]
417
- * @param {String} [type='image/png']
418
- * @memberof Debug */
419
- export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
420
- /**
421
- * LittleJS Utility Classes and Functions
422
- * - General purpose math library
423
- * - Vector2 - fast, simple, easy 2D vector class
424
- * - Color - holds a rgba color with some math functions
425
- * - Timer - tracks time automatically
426
- * - RandomGenerator - seeded random number generator
427
- * @namespace Utilities
428
- */
429
- /** A shortcut to get Math.PI
430
- * @type {Number}
431
- * @default Math.PI
432
- * @memberof Utilities */
433
- export const PI: number;
434
- /** Returns absoulte value of value passed in
435
- * @param {Number} value
436
- * @return {Number}
437
- * @memberof Utilities */
438
- export function abs(value: number): number;
439
- /** Returns lowest of two values passed in
440
- * @param {Number} valueA
441
- * @param {Number} valueB
442
- * @return {Number}
443
- * @memberof Utilities */
444
- export function min(valueA: number, valueB: number): number;
445
- /** Returns highest of two values passed in
446
- * @param {Number} valueA
447
- * @param {Number} valueB
448
- * @return {Number}
449
- * @memberof Utilities */
450
- export function max(valueA: number, valueB: number): number;
451
- /** Returns the sign of value passed in (also returns 1 if 0)
452
- * @param {Number} value
453
- * @return {Number}
454
- * @memberof Utilities */
455
- export function sign(value: number): number;
456
- /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
457
- * @param {Number} dividend
458
- * @param {Number} [divisor=1]
459
- * @return {Number}
460
- * @memberof Utilities */
461
- export function mod(dividend: number, divisor?: number): number;
462
- /** Clamps the value beween max and min
463
- * @param {Number} value
464
- * @param {Number} [min=0]
465
- * @param {Number} [max=1]
466
- * @return {Number}
467
- * @memberof Utilities */
468
- export function clamp(value: number, min?: number, max?: number): number;
469
- /** Returns what percentage the value is between valueA and valueB
470
- * @param {Number} value
471
- * @param {Number} valueA
472
- * @param {Number} valueB
473
- * @return {Number}
474
- * @memberof Utilities */
475
- export function percent(value: number, valueA: number, valueB: number): number;
476
- /** Returns signed wrapped distance between the two values passed in
477
- * @param {Number} valueA
478
- * @param {Number} valueB
479
- * @param {Number} [wrapSize=1]
480
- * @returns {Number}
481
- * @memberof Utilities */
482
- export function distanceWrap(valueA: number, valueB: number, wrapSize?: number): number;
483
- /** Linearly interpolates between values passed in with wrappping
484
- * @param {Number} percent
485
- * @param {Number} valueA
486
- * @param {Number} valueB
487
- * @param {Number} [wrapSize=1]
488
- * @returns {Number}
489
- * @memberof Utilities */
490
- export function lerpWrap(percent: number, valueA: number, valueB: number, wrapSize?: number): number;
491
- /** Returns signed wrapped distance between the two angles passed in
492
- * @param {Number} angleA
493
- * @param {Number} angleB
494
- * @returns {Number}
495
- * @memberof Utilities */
496
- export function distanceAngle(angleA: number, angleB: number): number;
497
- /** Linearly interpolates between the angles passed in with wrappping
498
- * @param {Number} percent
499
- * @param {Number} angleA
500
- * @param {Number} angleB
501
- * @returns {Number}
502
- * @memberof Utilities */
503
- export function lerpAngle(percent: number, angleA: number, angleB: number): number;
504
- /** Linearly interpolates between values passed in using percent
505
- * @param {Number} percent
506
- * @param {Number} valueA
507
- * @param {Number} valueB
508
- * @return {Number}
509
- * @memberof Utilities */
510
- export function lerp(percent: number, valueA: number, valueB: number): number;
511
- /** Applies smoothstep function to the percentage value
512
- * @param {Number} percent
513
- * @return {Number}
514
- * @memberof Utilities */
515
- export function smoothStep(percent: number): number;
516
- /** Returns the nearest power of two not less then the value
517
- * @param {Number} value
518
- * @return {Number}
519
- * @memberof Utilities */
520
- export function nearestPowerOfTwo(value: number): number;
521
- /** Returns true if two axis aligned bounding boxes are overlapping
522
- * @param {Vector2} pointA - Center of box A
523
- * @param {Vector2} sizeA - Size of box A
524
- * @param {Vector2} pointB - Center of box B
525
- * @param {Vector2} sizeB - Size of box B
526
- * @return {Boolean} - True if overlapping
527
- * @memberof Utilities */
528
- export function isOverlapping(pointA: Vector2, sizeA: Vector2, pointB: Vector2, sizeB: Vector2): boolean;
529
- /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
530
- * @param {Number} [frequency=1] - Frequency of the wave in Hz
531
- * @param {Number} [amplitude=1] - Amplitude (max height) of the wave
532
- * @param {Number} [t=time] - Value to use for time of the wave
533
- * @return {Number} - Value waving between 0 and amplitude
534
- * @memberof Utilities */
535
- export function wave(frequency?: number, amplitude?: number, t?: number): number;
536
- /** Formats seconds to mm:ss style for display purposes
537
- * @param {Number} t - time in seconds
538
- * @return {String}
539
- * @memberof Utilities */
540
- export function formatTime(t: number): string;
541
- /** Random global functions
542
- * @namespace Random */
543
- /** Returns a random value between the two values passed in
544
- * @param {Number} [valueA=1]
545
- * @param {Number} [valueB=0]
546
- * @return {Number}
547
- * @memberof Random */
548
- export function rand(valueA?: number, valueB?: number): number;
549
- /** Returns a floored random value the two values passed in
550
- * @param {Number} valueA
551
- * @param {Number} [valueB=0]
552
- * @return {Number}
553
- * @memberof Random */
554
- export function randInt(valueA: number, valueB?: number): number;
555
- /** Randomly returns either -1 or 1
556
- * @return {Number}
557
- * @memberof Random */
558
- export function randSign(): number;
559
- /** Returns a random Vector2 within a circular shape
560
- * @param {Number} [radius=1]
561
- * @param {Number} [minRadius=0]
562
- * @return {Vector2}
563
- * @memberof Random */
564
- export function randInCircle(radius?: number, minRadius?: number): Vector2;
565
- /** Returns a random Vector2 with the passed in length
566
- * @param {Number} [length=1]
567
- * @return {Vector2}
568
- * @memberof Random */
569
- export function randVector(length?: number): Vector2;
570
- /** Returns a random color between the two passed in colors, combine components if linear
571
- * @param {Color} [colorA=Color()]
572
- * @param {Color} [colorB=Color(0,0,0,1)]
573
- * @param {Boolean} [linear]
574
- * @return {Color}
575
- * @memberof Random */
576
- export function randColor(colorA?: Color, colorB?: Color, linear?: boolean): Color;
577
- /**
578
- * Seeded random number generator
579
- * - Can be used to create a deterministic random number sequence
580
- * @example
581
- * let r = new RandomGenerator(123); // random number generator with seed 123
582
- * let a = r.float(); // random value between 0 and 1
583
- * let b = r.int(10); // random integer between 0 and 9
584
- * r.seed = 123; // reset the seed
585
- * let c = r.float(); // the same value as a
586
- */
587
- export class RandomGenerator {
588
- /** Create a random number generator with the seed passed in
589
- * @param {Number} seed - Starting seed */
590
- constructor(seed: number);
591
- /** @property {Number} - random seed */
592
- seed: number;
593
- /** Returns a seeded random value between the two values passed in
594
- * @param {Number} [valueA=1]
595
- * @param {Number} [valueB=0]
596
- * @return {Number} */
597
- float(valueA?: number, valueB?: number): number;
598
- /** Returns a floored seeded random value the two values passed in
599
- * @param {Number} valueA
600
- * @param {Number} [valueB=0]
601
- * @return {Number} */
602
- int(valueA: number, valueB?: number): number;
603
- /** Randomly returns either -1 or 1 deterministically
604
- * @return {Number} */
605
- sign(): number;
606
- }
607
- /**
608
- * 2D Vector object with vector math library
609
- * - Functions do not change this so they can be chained together
610
- * @example
611
- * let a = new Vector2(2, 3); // vector with coordinates (2, 3)
612
- * let b = new Vector2; // vector with coordinates (0, 0)
613
- * let c = vec2(4, 2); // use the vec2 function to make a Vector2
614
- * let d = a.add(b).scale(5); // operators can be chained
615
- */
616
- export class Vector2 {
617
- /** Create a 2D vector with the x and y passed in, can also be created with vec2()
618
- * @param {Number} [x=0] - X axis location
619
- * @param {Number} [y=0] - Y axis location */
620
- constructor(x?: number, y?: number);
621
- /** @property {Number} - X axis location */
622
- x: number;
623
- /** @property {Number} - Y axis location */
624
- y: number;
625
- /** Returns a new vector that is a copy of this
626
- * @return {Vector2} */
627
- copy(): Vector2;
628
- /** Returns a copy of this vector plus the vector passed in
629
- * @param {Vector2} v - other vector
630
- * @return {Vector2} */
631
- add(v: Vector2): Vector2;
632
- /** Returns a copy of this vector minus the vector passed in
633
- * @param {Vector2} v - other vector
634
- * @return {Vector2} */
635
- subtract(v: Vector2): Vector2;
636
- /** Returns a copy of this vector times the vector passed in
637
- * @param {Vector2} v - other vector
638
- * @return {Vector2} */
639
- multiply(v: Vector2): Vector2;
640
- /** Returns a copy of this vector divided by the vector passed in
641
- * @param {Vector2} v - other vector
642
- * @return {Vector2} */
643
- divide(v: Vector2): Vector2;
644
- /** Returns a copy of this vector scaled by the vector passed in
645
- * @param {Number} s - scale
646
- * @return {Vector2} */
647
- scale(s: number): Vector2;
648
- /** Returns the length of this vector
649
- * @return {Number} */
650
- length(): number;
651
- /** Returns the length of this vector squared
652
- * @return {Number} */
653
- lengthSquared(): number;
654
- /** Returns the distance from this vector to vector passed in
655
- * @param {Vector2} v - other vector
656
- * @return {Number} */
657
- distance(v: Vector2): number;
658
- /** Returns the distance squared from this vector to vector passed in
659
- * @param {Vector2} v - other vector
660
- * @return {Number} */
661
- distanceSquared(v: Vector2): number;
662
- /** Returns a new vector in same direction as this one with the length passed in
663
- * @param {Number} [length=1]
664
- * @return {Vector2} */
665
- normalize(length?: number): Vector2;
666
- /** Returns a new vector clamped to length passed in
667
- * @param {Number} [length=1]
668
- * @return {Vector2} */
669
- clampLength(length?: number): Vector2;
670
- /** Returns the dot product of this and the vector passed in
671
- * @param {Vector2} v - other vector
672
- * @return {Number} */
673
- dot(v: Vector2): number;
674
- /** Returns the cross product of this and the vector passed in
675
- * @param {Vector2} v - other vector
676
- * @return {Number} */
677
- cross(v: Vector2): number;
678
- /** Returns the angle of this vector, up is angle 0
679
- * @return {Number} */
680
- angle(): number;
681
- /** Sets this vector with angle and length passed in
682
- * @param {Number} [angle=0]
683
- * @param {Number} [length=1]
684
- * @return {Vector2} */
685
- setAngle(angle?: number, length?: number): Vector2;
686
- /** Returns copy of this vector rotated by the angle passed in
687
- * @param {Number} angle
688
- * @return {Vector2} */
689
- rotate(angle: number): Vector2;
690
- /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
691
- * @return {Number} */
692
- direction(): number;
693
- /** Returns a copy of this vector that has been inverted
694
- * @return {Vector2} */
695
- invert(): Vector2;
696
- /** Returns a copy of this vector with each axis floored
697
- * @return {Vector2} */
698
- floor(): Vector2;
699
- /** Returns the area this vector covers as a rectangle
700
- * @return {Number} */
701
- area(): number;
702
- /** Returns a new vector that is p percent between this and the vector passed in
703
- * @param {Vector2} v - other vector
704
- * @param {Number} percent
705
- * @return {Vector2} */
706
- lerp(v: Vector2, percent: number): Vector2;
707
- /** Returns true if this vector is within the bounds of an array size passed in
708
- * @param {Vector2} arraySize
709
- * @return {Boolean} */
710
- arrayCheck(arraySize: Vector2): boolean;
711
- /** Returns this vector expressed as a string
712
- * @param {float} digits - precision to display
713
- * @return {String} */
714
- toString(digits?: float): string;
715
- }
716
- /**
717
- * Color object (red, green, blue, alpha) with some helpful functions
718
- * @example
719
- * let a = new Color; // white
720
- * let b = new Color(1, 0, 0); // red
721
- * let c = new Color(0, 0, 0, 0); // transparent black
722
- * let d = RGB(0, 0, 1); // blue using rgb color
723
- * let e = HSL(.3, 1, .5); // green using hsl color
724
- */
725
- export class Color {
726
- /** Create a color with the rgba components passed in, white by default
727
- * @param {Number} [r=1] - red
728
- * @param {Number} [g=1] - green
729
- * @param {Number} [b=1] - blue
730
- * @param {Number} [a=1] - alpha*/
731
- constructor(r?: number, g?: number, b?: number, a?: number);
732
- /** @property {Number} - Red */
733
- r: number;
734
- /** @property {Number} - Green */
735
- g: number;
736
- /** @property {Number} - Blue */
737
- b: number;
738
- /** @property {Number} - Alpha */
739
- a: number;
740
- /** Returns a new color that is a copy of this
741
- * @return {Color} */
742
- copy(): Color;
743
- /** Returns a copy of this color plus the color passed in
744
- * @param {Color} c - other color
745
- * @return {Color} */
746
- add(c: Color): Color;
747
- /** Returns a copy of this color minus the color passed in
748
- * @param {Color} c - other color
749
- * @return {Color} */
750
- subtract(c: Color): Color;
751
- /** Returns a copy of this color times the color passed in
752
- * @param {Color} c - other color
753
- * @return {Color} */
754
- multiply(c: Color): Color;
755
- /** Returns a copy of this color divided by the color passed in
756
- * @param {Color} c - other color
757
- * @return {Color} */
758
- divide(c: Color): Color;
759
- /** Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
760
- * @param {Number} scale
761
- * @param {Number} [alphaScale=scale]
762
- * @return {Color} */
763
- scale(scale: number, alphaScale?: number): Color;
764
- /** Returns a copy of this color clamped to the valid range between 0 and 1
765
- * @return {Color} */
766
- clamp(): Color;
767
- /** Returns a new color that is p percent between this and the color passed in
768
- * @param {Color} c - other color
769
- * @param {Number} percent
770
- * @return {Color} */
771
- lerp(c: Color, percent: number): Color;
772
- /** Sets this color given a hue, saturation, lightness, and alpha
773
- * @param {Number} [h=0] - hue
774
- * @param {Number} [s=0] - saturation
775
- * @param {Number} [l=1] - lightness
776
- * @param {Number} [a=1] - alpha
777
- * @return {Color} */
778
- setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
779
- /** Returns this color expressed in hsla format
780
- * @return {Array} */
781
- getHSLA(): any[];
782
- /** Returns a new color that has each component randomly adjusted
783
- * @param {Number} [amount=.05]
784
- * @param {Number} [alphaAmount=0]
785
- * @return {Color} */
786
- mutate(amount?: number, alphaAmount?: number): Color;
787
- /** Returns this color expressed as a hex color code
788
- * @param {Boolean} [useAlpha=1] - if alpha should be included in result
789
- * @return {String} */
790
- toString(useAlpha?: boolean): string;
791
- /** Set this color from a hex code
792
- * @param {String} hex - html hex code
793
- * @return {Color} */
794
- setHex(hex: string): Color;
795
- /** Returns this color expressed as 32 bit RGBA value
796
- * @return {Number} */
797
- rgbaInt(): number;
798
- }
799
- /**
800
- * Timer object tracks how long has passed since it was set
801
- * @example
802
- * let a = new Timer; // creates a timer that is not set
803
- * a.set(3); // sets the timer to 3 seconds
804
- *
805
- * let b = new Timer(1); // creates a timer with 1 second left
806
- * b.unset(); // unsets the timer
807
- */
808
- export class Timer {
809
- /** Create a timer object set time passed in
810
- * @param {Number} [timeLeft] - How much time left before the timer elapses in seconds */
811
- constructor(timeLeft?: number);
812
- time: number;
813
- setTime: number;
814
- /** Set the timer with seconds passed in
815
- * @param {Number} [timeLeft=0] - How much time left before the timer is elapsed in seconds */
816
- set(timeLeft?: number): void;
817
- /** Unset the timer */
818
- unset(): void;
819
- /** Returns true if set
820
- * @return {Boolean} */
821
- isSet(): boolean;
822
- /** Returns true if set and has not elapsed
823
- * @return {Boolean} */
824
- active(): boolean;
825
- /** Returns true if set and elapsed
826
- * @return {Boolean} */
827
- elapsed(): boolean;
828
- /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
829
- * @return {Number} */
830
- get(): number;
831
- /** Get percentage elapsed based on time it was set to, returns 0 if not set
832
- * @return {Number} */
833
- getPercent(): number;
834
- /** Returns this timer expressed as a string
835
- * @return {String} */
836
- toString(): string;
837
- /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
838
- * @return {Number} */
839
- valueOf(): number;
840
- }
841
- /**
842
- * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
843
- * @param {(Number|Vector2)} [x=0]
844
- * @param {Number} [y=0]
845
- * @return {Vector2}
846
- * @example
847
- * let a = vec2(0, 1); // vector with coordinates (0, 1)
848
- * let b = vec2(a); // copy a into b
849
- * a = vec2(5); // set a to (5, 5)
850
- * b = vec2(); // set b to (0, 0)
851
- * @memberof Utilities
852
- */
853
- export function vec2(x?: (number | Vector2), y?: number): Vector2;
854
- /**
855
- * Create a color object with RGBA values
856
- * @param {Number} [r=1] - red
857
- * @param {Number} [g=1] - green
858
- * @param {Number} [b=1] - blue
859
- * @param {Number} [a=1] - alpha
860
- * @return {Color}
861
- * @memberof Utilities
862
- */
863
- export function rgb(r?: number, g?: number, b?: number, a?: number): Color;
864
- /**
865
- * Create a color object with HSLA values
866
- * @param {Number} [h=0] - hue
867
- * @param {Number} [s=0] - saturation
868
- * @param {Number} [l=1] - lightness
869
- * @param {Number} [a=1] - alpha
870
- * @return {Color}
871
- * @memberof Utilities
872
- */
873
- export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
874
- /**
875
- * LittleJS Object System
876
- */
877
- /**
878
- * LittleJS Object Base Object Class
879
- * - Top level object class used by the engine
880
- * - Automatically adds self to object list
881
- * - Will be updated and rendered each frame
882
- * - Renders as a sprite from a tilesheet by default
883
- * - Can have color and addtive color applied
884
- * - 2D Physics and collision system
885
- * - Sorted by renderOrder
886
- * - Objects can have children attached
887
- * - Parents are updated before children, and set child transform
888
- * - Call destroy() to get rid of objects
889
- *
890
- * The physics system used by objects is simple and fast with some caveats...
891
- * - Collision uses the axis aligned size, the object's rotation angle is only for rendering
892
- * - Objects are guaranteed to not intersect tile collision from physics
893
- * - If an object starts or is moved inside tile collision, it will not collide with that tile
894
- * - Collision for objects can be set to be solid to block other objects
895
- * - Objects may get pushed into overlapping other solid objects, if so they will push away
896
- * - Solid objects are more performance intensive and should be used sparingly
897
- * @example
898
- * // create an engine object, normally you would first extend the class with your own
899
- * const pos = vec2(2,3);
900
- * const object = new EngineObject(pos);
901
- */
902
- export class EngineObject {
903
- /** Create an engine object and adds it to the list of objects
904
- * @param {Vector2} [pos=Vector2()] - World space position of the object
905
- * @param {Vector2} [size=Vector2(1,1)] - World space size of the object
906
- * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
907
- * @param {Number} [angle=0] - Angle the object is rotated by
908
- * @param {Color} [color=Color()] - Color to apply to tile when rendered
909
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
910
- */
911
- constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
912
- /** @property {Vector2} - World space position of the object */
913
- pos: Vector2;
914
- /** @property {Vector2} - World space width and height of the object */
915
- size: Vector2;
916
- /** @property {TileInfo} - Tile info to render object (undefined is untextured) */
917
- tileInfo: TileInfo;
918
- /** @property {Number} - Angle to rotate the object */
919
- angle: number;
920
- /** @property {Color} - Color to apply when rendered */
921
- color: Color;
922
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
923
- mass: number;
924
- /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
925
- damping: number;
926
- /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
927
- angleDamping: number;
928
- /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
929
- elasticity: number;
930
- /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
931
- friction: number;
932
- /** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
933
- gravityScale: number;
934
- /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
935
- renderOrder: number;
936
- /** @property {Vector2} [velocity=Vector2()] - Velocity of the object */
937
- velocity: Vector2;
938
- /** @property {Number} [angleVelocity=0] - Angular velocity of the object */
939
- angleVelocity: number;
940
- spawnTime: number;
941
- children: any[];
942
- collideTiles: number;
943
- /** Update the object transform and physics, called automatically by engine once each frame */
944
- update(): void;
945
- groundObject: any;
946
- /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
947
- render(): void;
948
- /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
949
- destroy(): void;
950
- destroyed: number;
951
- /** Called to check if a tile collision should be resolved
952
- * @param {Number} tileData - the value of the tile at the position
953
- * @param {Vector2} pos - tile where the collision occured
954
- * @return {Boolean} - true if the collision should be resolved */
955
- collideWithTile(tileData: number, pos: Vector2): boolean;
956
- /** Called to check if a tile raycast hit
957
- * @param {Number} tileData - the value of the tile at the position
958
- * @param {Vector2} pos - tile where the raycast is
959
- * @return {Boolean} - true if the raycast should hit */
960
- collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
961
- /** Called to check if a object collision should be resolved
962
- * @param {EngineObject} object - the object to test against
963
- * @return {Boolean} - true if the collision should be resolved
964
- */
965
- collideWithObject(object: EngineObject): boolean;
966
- /** How long since the object was created
967
- * @return {Number} */
968
- getAliveTime(): number;
969
- /** Apply acceleration to this object (adjust velocity, not affected by mass)
970
- * @param {Vector2} acceleration */
971
- applyAcceleration(acceleration: Vector2): void;
972
- /** Apply force to this object (adjust velocity, affected by mass)
973
- * @param {Vector2} force */
974
- applyForce(force: Vector2): void;
975
- /** Get the direction of the mirror
976
- * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */
977
- getMirrorSign(): number;
978
- /** Attaches a child to this with a given local transform
979
- * @param {EngineObject} child
980
- * @param {Vector2} [localPos=Vector2()]
981
- * @param {Number} [localAngle=0] */
982
- addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): void;
983
- /** Removes a child from this one
984
- * @param {EngineObject} child */
985
- removeChild(child: EngineObject): void;
986
- /** Set how this object collides
987
- * @param {Boolean} [collideSolidObjects=1] - Does it collide with solid objects
988
- * @param {Boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
989
- * @param {Boolean} [collideTiles=1] - Does it collide with the tile collision */
990
- setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
991
- collideSolidObjects: boolean;
992
- isSolid: boolean;
993
- /** Returns string containg info about this object for debugging
994
- * @return {String} */
995
- toString(): string;
996
- }
997
- /** Array containing texture info for batch rendering system
998
- * @type {Array}
999
- * @memberof Draw */
1000
- export let textureInfos: any[];
1001
- /**
1002
- * Create a tile info object
1003
- * - This can take vecs or floats for easier use and conversion
1004
- * - If an index is passed in, the tile size and index will determine the position
1005
- * @param {(Number|Vector2)} [pos=Vector2()] - Top left corner of tile in pixels or index
1006
- * @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
1007
- * @param {Number} [textureIndex=0] - Texture index to use
1008
- * @return {TileInfo}
1009
- * @example
1010
- * tile(2) // a tile at index 2 using the default tile size of 16
1011
- * tile(5, 8) // a tile at index 5 using a tile size of 8
1012
- * tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
1013
- * tile(vec2(4,8), vec2(30,10)) // a tile at pixel location (4,8) with a size of (30,10)
1014
- * @memberof Draw
1015
- */
1016
- export function tile(pos?: (number | Vector2), size?: (number | Vector2), textureIndex?: number): TileInfo;
1017
- /**
1018
- * Tile Info - Stores info about how to draw a tile
1019
- */
1020
- export class TileInfo {
1021
- /** Create a tile info object
1022
- * @param {Vector2} [pos=Vector2()] - Top left corner of tile in pixels
1023
- * @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
1024
- * @param {Number} [textureIndex=0] - Texture index to use
1025
- */
1026
- constructor(pos?: Vector2, size?: Vector2, textureIndex?: number);
1027
- /** @property {Vector2} - Top left corner of tile in pixels */
1028
- pos: Vector2;
1029
- /** @property {Vector2} - Size of tile in pixels */
1030
- size: Vector2;
1031
- /** @property {Number} - Texture index to use */
1032
- textureIndex: number;
1033
- /** Returns an offset copy of this tile, useful for animation
1034
- * @param {Vector2} offset - Offset to apply in pixels
1035
- * @return {TileInfo}
1036
- */
1037
- offset(offset: Vector2): TileInfo;
1038
- /** Returns the texture info for this tile
1039
- * @return {TextureInfo}
1040
- */
1041
- getTextureInfo(): TextureInfo;
1042
- }
1043
- /** Texture Info - Stores info about each texture */
1044
- export class TextureInfo {
1045
- constructor(image: any);
1046
- /** @property {CanvasImageSource} - image source */
1047
- image: any;
1048
- /** @property {Vector2} - size of the image */
1049
- size: Vector2;
1050
- /** @property {WebGLTexture} - webgl texture */
1051
- glTexture: WebGLTexture;
1052
- /** @property {Vector2} - size to adjust tile to fix bleeding */
1053
- fixBleedSize: Vector2;
1054
- }
1055
- /**
1056
- * LittleJS Drawing System
1057
- * - Hybrid system with both Canvas2D and WebGL available
1058
- * - Super fast tile sheet rendering with WebGL
1059
- * - Can apply rotation, mirror, color and additive color
1060
- * - Font rendering system with built in engine font
1061
- * - Many useful utility functions
1062
- *
1063
- * LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.
1064
- * There are 3 canvas/contexts available to draw to...
1065
- * mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
1066
- * glCanvas - Used by the accelerated WebGL batch rendering system.
1067
- * overlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.
1068
- *
1069
- * The WebGL rendering system is very fast with some caveats...
1070
- * - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
1071
- * - Group additive rendering together using renderOrder to mitigate this issue
1072
- *
1073
- * The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!
1074
- * @namespace Draw
1075
- */
1076
- /** The primary 2D canvas visible to the user
1077
- * @type {HTMLCanvasElement}
1078
- * @memberof Draw */
1079
- export let mainCanvas: HTMLCanvasElement;
1080
- /** 2d context for mainCanvas
1081
- * @type {CanvasRenderingContext2D}
1082
- * @memberof Draw */
1083
- export let mainContext: CanvasRenderingContext2D;
1084
- /** A canvas that appears on top of everything the same size as mainCanvas
1085
- * @type {HTMLCanvasElement}
1086
- * @memberof Draw */
1087
- export let overlayCanvas: HTMLCanvasElement;
1088
- /** 2d context for overlayCanvas
1089
- * @type {CanvasRenderingContext2D}
1090
- * @memberof Draw */
1091
- export let overlayContext: CanvasRenderingContext2D;
1092
- /** The size of the main canvas (and other secondary canvases)
1093
- * @type {Vector2}
1094
- * @memberof Draw */
1095
- export let mainCanvasSize: Vector2;
1096
- /** Convert from screen to world space coordinates
1097
- * @param {Vector2} screenPos
1098
- * @return {Vector2}
1099
- * @memberof Draw */
1100
- export function screenToWorld(screenPos: Vector2): Vector2;
1101
- /** Convert from world to screen space coordinates
1102
- * @param {Vector2} worldPos
1103
- * @return {Vector2}
1104
- * @memberof Draw */
1105
- export function worldToScreen(worldPos: Vector2): Vector2;
1106
- /** Draw textured tile centered in world space, with color applied if using WebGL
1107
- * @param {Vector2} pos - Center of the tile in world space
1108
- * @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
1109
- * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
1110
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
1111
- * @param {Color} [color=Color()] - Color to modulate with
1112
- * @param {Number} [angle=0] - Angle to rotate by
1113
- * @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
1114
- * @param {Color} [additiveColor=Color(0,0,0,0)] - Additive color to be applied
1115
- * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1116
- * @param {Boolean} [screenSpace=0] - If true the pos and size are in screen space
1117
- * @memberof Draw */
1118
- export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean): void;
1119
- /** Draw colored rect centered on pos
1120
- * @param {Vector2} pos
1121
- * @param {Vector2} [size=Vector2(1,1)]
1122
- * @param {Color} [color=Color()]
1123
- * @param {Number} [angle=0]
1124
- * @param {Boolean} [useWebGL=glEnable]
1125
- * @param {Boolean} [screenSpace=0]
1126
- * @memberof Draw */
1127
- export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean): void;
1128
- /** Draw colored line between two points
1129
- * @param {Vector2} posA
1130
- * @param {Vector2} posB
1131
- * @param {Number} [thickness=.1]
1132
- * @param {Color} [color=Color()]
1133
- * @param {Boolean} [useWebGL=glEnable]
1134
- * @param {Boolean} [screenSpace=0]
1135
- * @memberof Draw */
1136
- export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean, screenSpace?: boolean): void;
1137
- /** Draw directly to a 2d canvas context in world space
1138
- * @param {Vector2} pos
1139
- * @param {Vector2} size
1140
- * @param {Number} angle
1141
- * @param {Boolean} mirror
1142
- * @param {Function} drawFunction
1143
- * @param {CanvasRenderingContext2D} [context=mainContext]
1144
- * @param {Boolean} [screenSpace=0]
1145
- * @memberof Draw */
1146
- export function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, context?: CanvasRenderingContext2D, screenSpace?: boolean): void;
1147
- /** Enable normal or additive blend mode
1148
- * @param {Boolean} [additive=0]
1149
- * @param {Boolean} [useWebGL=glEnable]
1150
- * @memberof Draw */
1151
- export function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
1152
- /** Draw text on overlay canvas in screen space
1153
- * Automatically splits new lines into rows
1154
- * @param {String} text
1155
- * @param {Vector2} pos
1156
- * @param {Number} [size=1]
1157
- * @param {Color} [color=Color()]
1158
- * @param {Number} [lineWidth=0]
1159
- * @param {Color} [lineColor=Color(0,0,0)]
1160
- * @param {String} [textAlign='center']
1161
- * @param {String} [font=fontDefault]
1162
- * @param {CanvasRenderingContext2D} [context=overlayContext]
1163
- * @memberof Draw */
1164
- export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
1165
- /** Draw text on overlay canvas in world space
1166
- * Automatically splits new lines into rows
1167
- * @param {String} text
1168
- * @param {Vector2} pos
1169
- * @param {Number} [size=1]
1170
- * @param {Color} [color=Color()]
1171
- * @param {Number} [lineWidth=0]
1172
- * @param {Color} [lineColor=Color(0,0,0)]
1173
- * @param {String} [textAlign='center']
1174
- * @param {String} [font=fontDefault]
1175
- * @param {CanvasRenderingContext2D} [context=overlayContext]
1176
- * @memberof Draw */
1177
- export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
1178
- export let engineFontImage: any;
1179
- /**
1180
- * Font Image Object - Draw text on a 2D canvas by using characters in an image
1181
- * - 96 characters (from space to tilde) are stored in an image
1182
- * - Uses a default 8x8 font if none is supplied
1183
- * - You can also use fonts from the main tile sheet
1184
- * @example
1185
- * // use built in font
1186
- * const font = new ImageFont;
1187
- *
1188
- * // draw text
1189
- * font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
1190
- */
1191
- export class FontImage {
1192
- /** Create an image font
1193
- * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1194
- * @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
1195
- * @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
1196
- * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
1197
- */
1198
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1199
- image: any;
1200
- tileSize: Vector2;
1201
- paddingSize: Vector2;
1202
- context: CanvasRenderingContext2D;
1203
- /** Draw text in world space using the image font
1204
- * @param {String} text
1205
- * @param {Vector2} pos
1206
- * @param {Number} [scale=.25]
1207
- * @param {Boolean} [center]
1208
- */
1209
- drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1210
- /** Draw text in screen space using the image font
1211
- * @param {String} text
1212
- * @param {Vector2} pos
1213
- * @param {Number} [scale=4]
1214
- * @param {Boolean} [center]
1215
- */
1216
- drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1217
- }
1218
- /** Returns true if fullscreen mode is active
1219
- * @return {Boolean}
1220
- * @memberof Draw */
1221
- export function isFullscreen(): boolean;
1222
- /** Toggle fullsceen mode
1223
- * @memberof Draw */
1224
- export function toggleFullscreen(): void;
1225
- /**
1226
- * LittleJS Input System
1227
- * - Tracks keyboard down, pressed, and released
1228
- * - Tracks mouse buttons, position, and wheel
1229
- * - Tracks multiple analog gamepads
1230
- * - Virtual gamepad for touch devices
1231
- * @namespace Input
1232
- */
1233
- /** Returns true if device key is down
1234
- * @param {Number} key
1235
- * @param {Number} [device=0]
1236
- * @return {Boolean}
1237
- * @memberof Input */
1238
- export function keyIsDown(key: number, device?: number): boolean;
1239
- /** Returns true if device key was pressed this frame
1240
- * @param {Number} key
1241
- * @param {Number} [device=0]
1242
- * @return {Boolean}
1243
- * @memberof Input */
1244
- export function keyWasPressed(key: number, device?: number): boolean;
1245
- /** Returns true if device key was released this frame
1246
- * @param {Number} key
1247
- * @param {Number} [device=0]
1248
- * @return {Boolean}
1249
- * @memberof Input */
1250
- export function keyWasReleased(key: number, device?: number): boolean;
1251
- /** Clears all input
1252
- * @memberof Input */
1253
- export function clearInput(): void;
1254
- /**
1255
- * LittleJS Input System
1256
- * - Tracks keyboard down, pressed, and released
1257
- * - Tracks mouse buttons, position, and wheel
1258
- * - Tracks multiple analog gamepads
1259
- * - Virtual gamepad for touch devices
1260
- * @namespace Input
1261
- */
1262
- /** Returns true if device key is down
1263
- * @param {Number} key
1264
- * @param {Number} [device=0]
1265
- * @return {Boolean}
1266
- * @memberof Input */
1267
- export function mouseIsDown(key: number, device?: number): boolean;
1268
- /** Returns true if device key was pressed this frame
1269
- * @param {Number} key
1270
- * @param {Number} [device=0]
1271
- * @return {Boolean}
1272
- * @memberof Input */
1273
- export function mouseWasPressed(key: number, device?: number): boolean;
1274
- /** Returns true if device key was released this frame
1275
- * @param {Number} key
1276
- * @param {Number} [device=0]
1277
- * @return {Boolean}
1278
- * @memberof Input */
1279
- export function mouseWasReleased(key: number, device?: number): boolean;
1280
- /** Mouse pos in world space
1281
- * @type {Vector2}
1282
- * @memberof Input */
1283
- export let mousePos: Vector2;
1284
- /** Mouse pos in screen space
1285
- * @type {Vector2}
1286
- * @memberof Input */
1287
- export let mousePosScreen: Vector2;
1288
- /** Mouse wheel delta this frame
1289
- * @type {Number}
1290
- * @memberof Input */
1291
- export let mouseWheel: number;
1292
- /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1293
- * @type {Boolean}
1294
- * @memberof Input */
1295
- export let isUsingGamepad: boolean;
1296
- /** Prevents input continuing to the default browser handling (false by default)
1297
- * @type {Boolean}
1298
- * @memberof Input */
1299
- export let preventDefaultInput: boolean;
1300
- /** Returns true if gamepad button is down
1301
- * @param {Number} button
1302
- * @param {Number} [gamepad=0]
1303
- * @return {Boolean}
1304
- * @memberof Input */
1305
- export function gamepadIsDown(button: number, gamepad?: number): boolean;
1306
- /** Returns true if gamepad button was pressed
1307
- * @param {Number} button
1308
- * @param {Number} [gamepad=0]
1309
- * @return {Boolean}
1310
- * @memberof Input */
1311
- export function gamepadWasPressed(button: number, gamepad?: number): boolean;
1312
- /** Returns true if gamepad button was released
1313
- * @param {Number} button
1314
- * @param {Number} [gamepad=0]
1315
- * @return {Boolean}
1316
- * @memberof Input */
1317
- export function gamepadWasReleased(button: number, gamepad?: number): boolean;
1318
- /** Returns gamepad stick value
1319
- * @param {Number} stick
1320
- * @param {Number} [gamepad=0]
1321
- * @return {Vector2}
1322
- * @memberof Input */
1323
- export function gamepadStick(stick: number, gamepad?: number): Vector2;
1324
- export function mouseToScreen(mousePos: any): Vector2;
1325
- export function gamepadsUpdate(): void;
1326
- /** Pulse the vibration hardware if it exists
1327
- * @param {Number} [pattern=100] - a single value in miliseconds or vibration interval array
1328
- * @memberof Input */
1329
- export function vibrate(pattern?: number): void;
1330
- /** Cancel any ongoing vibration
1331
- * @memberof Input */
1332
- export function vibrateStop(): void;
1333
- /** True if a touch device has been detected
1334
- * @memberof Input */
1335
- export const isTouchDevice: boolean;
1336
- /**
1337
- * LittleJS Audio System
1338
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1339
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1340
- * - Caches sounds and music for fast playback
1341
- * - Can attenuate and apply stereo panning to sounds
1342
- * - Ability to play mp3, ogg, and wave files
1343
- * - Speech synthesis functions
1344
- * @namespace Audio
1345
- */
1346
- /**
1347
- * Sound Object - Stores a zzfx sound for later use and can be played positionally
1348
- *
1349
- * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
1350
- * @example
1351
- * // create a sound
1352
- * const sound_example = new Sound([.5,.5]);
1353
- *
1354
- * // play the sound
1355
- * sound_example.play();
1356
- */
1357
- export class Sound {
1358
- /** Create a sound object and cache the zzfx samples for later use
1359
- * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
1360
- * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1361
- * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1362
- */
1363
- constructor(zzfxSound: any[], range?: number, taper?: number);
1364
- /** @property {Number} - World space max range of sound, will not play if camera is farther away */
1365
- range: number;
1366
- /** @property {Number} - At what percentage of range should it start tapering off */
1367
- taper: number;
1368
- /** @property {Number} - How much to randomize frequency each time sound plays */
1369
- randomness: any;
1370
- sampleChannels: any[][];
1371
- sampleRate: number;
1372
- /** Play the sound
1373
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1374
- * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1375
- * @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
1376
- * @param {Number} [randomnessScale=1] - How much to scale randomness
1377
- * @param {Boolean} [loop=0] - Should the sound loop
1378
- * @return {AudioBufferSourceNode} - The audio source node
1379
- */
1380
- play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1381
- source: number | AudioBufferSourceNode;
1382
- /** Stop the last instance of this sound that was played */
1383
- stop(): void;
1384
- /** Play the sound as a note with a semitone offset
1385
- * @param {Number} semitoneOffset - How many semitones to offset pitch
1386
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1387
- * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1388
- * @return {AudioBufferSourceNode} - The audio source node
1389
- */
1390
- playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1391
- /** Get how long this sound is in seconds
1392
- * @return {Number} - How long the sound is in seconds (undefined if loading)
1393
- */
1394
- getDuration(): number;
1395
- /** Check if the last instance of this sound is playing
1396
- * @return {Boolean} - True if the sound is playing
1397
- */
1398
- isPlaying(): boolean;
1399
- /** Check if sound is loading, for sounds fetched from a url
1400
- * @return {Boolean} - True if sound is loading and not ready to play
1401
- */
1402
- isLoading(): boolean;
1403
- }
1404
- /**
1405
- * Music Object - Stores a zzfx music track for later use
1406
- *
1407
- * <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
1408
- * @example
1409
- * // create some music
1410
- * const music_example = new Music(
1411
- * [
1412
- * [ // instruments
1413
- * [,0,400] // simple note
1414
- * ],
1415
- * [ // patterns
1416
- * [ // pattern 1
1417
- * [ // channel 0
1418
- * 0, -1, // instrument 0, left speaker
1419
- * 1, 0, 9, 1 // channel notes
1420
- * ],
1421
- * [ // channel 1
1422
- * 0, 1, // instrument 1, right speaker
1423
- * 0, 12, 17, -1 // channel notes
1424
- * ]
1425
- * ],
1426
- * ],
1427
- * [0, 0, 0, 0], // sequence, play pattern 0 four times
1428
- * 90 // BPM
1429
- * ]);
1430
- *
1431
- * // play the music
1432
- * music_example.play();
1433
- */
1434
- export class Music extends Sound {
1435
- /** Create a music object and cache the zzfx music samples for later use
1436
- * @param {Array} zzfxMusic - Array of zzfx music parameters
1437
- */
1438
- constructor(zzfxMusic: any[]);
1439
- sampleChannels: any[];
1440
- /** Play the music
1441
- * @param {Number} [volume=1] - How much to scale volume by
1442
- * @param {Boolean} [loop=1] - True if the music should loop
1443
- * @return {AudioBufferSourceNode} - The audio source node
1444
- */
1445
- play(volume?: number, loop?: boolean): AudioBufferSourceNode;
1446
- }
1447
- /** Play an mp3, ogg, or wav audio from a local file or url
1448
- * @param {String} url - Location of sound file to play
1449
- * @param {Number} [volume=1] - How much to scale volume by
1450
- * @param {Boolean} [loop=1] - True if the music should loop
1451
- * @return {HTMLAudioElement} - The audio element for this sound
1452
- * @memberof Audio */
1453
- export function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
1454
- /** Speak text with passed in settings
1455
- * @param {String} text - The text to speak
1456
- * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
1457
- * @param {Number} [volume=1] - How much to scale volume by
1458
- * @param {Number} [rate=1] - How quickly to speak
1459
- * @param {Number} [pitch=1] - How much to change the pitch by
1460
- * @return {SpeechSynthesisUtterance} - The utterance that was spoken
1461
- * @memberof Audio */
1462
- export function speak(text: string, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance;
1463
- /** Stop all queued speech
1464
- * @memberof Audio */
1465
- export function speakStop(): void;
1466
- /** Get frequency of a note on a musical scale
1467
- * @param {Number} semitoneOffset - How many semitones away from the root note
1468
- * @param {Number} [rootNoteFrequency=220] - Frequency at semitone offset 0
1469
- * @return {Number} - The frequency of the note
1470
- * @memberof Audio */
1471
- export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1472
- /** Audio context used by the engine
1473
- * @memberof Audio */
1474
- export let audioContext: any;
1475
- /** Play cached audio samples with given settings
1476
- * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1477
- * @param {Number} [volume=1] - How much to scale volume by
1478
- * @param {Number} [rate=1] - The playback rate to use
1479
- * @param {Number} [pan=0] - How much to apply stereo panning
1480
- * @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
1481
- * @param {Number} [sampleRate=44100] - Sample rate for the sound
1482
- * @return {AudioBufferSourceNode} - The audio node of the sound played
1483
- * @memberof Audio */
1484
- export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
1485
- /** Generate and play a ZzFX sound
1486
- *
1487
- * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
1488
- * @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
1489
- * @return {AudioBufferSourceNode} - The audio node of the sound played
1490
- * @memberof Audio */
1491
- export function zzfx(...zzfxSound: any[]): AudioBufferSourceNode;
1492
- /**
1493
- * LittleJS Tile Layer System
1494
- * - Caches arrays of tiles to off screen canvas for fast rendering
1495
- * - Unlimted numbers of layers, allocates canvases as needed
1496
- * - Interfaces with EngineObject for collision
1497
- * - Collision layer is separate from visible layers
1498
- * - It is recommended to have a visible layer that matches the collision
1499
- * - Tile layers can be drawn to using their context with canvas2d
1500
- * - Drawn directly to the main canvas without using WebGL
1501
- * @namespace TileCollision
1502
- */
1503
- /** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
1504
- * @type {Array}
1505
- * @memberof TileCollision */
1506
- export let tileCollision: any[];
1507
- /** Size of the tile collision layer
1508
- * @type {Vector2}
1509
- * @memberof TileCollision */
1510
- export let tileCollisionSize: Vector2;
1511
- /** Clear and initialize tile collision
1512
- * @param {Vector2} size
1513
- * @memberof TileCollision */
1514
- export function initTileCollision(size: Vector2): void;
1515
- /** Set tile collision data
1516
- * @param {Vector2} pos
1517
- * @param {Number} [data=0]
1518
- * @memberof TileCollision */
1519
- export function setTileCollisionData(pos: Vector2, data?: number): void;
1520
- /** Get tile collision data
1521
- * @param {Vector2} pos
1522
- * @return {Number}
1523
- * @memberof TileCollision */
1524
- export function getTileCollisionData(pos: Vector2): number;
1525
- /** Check if collision with another object should occur
1526
- * @param {Vector2} pos
1527
- * @param {Vector2} [size=Vector2(1,1)]
1528
- * @param {EngineObject} [object]
1529
- * @return {Boolean}
1530
- * @memberof TileCollision */
1531
- export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
1532
- /** Return the center of tile if any that is hit (does not return the exact intersection)
1533
- * @param {Vector2} posStart
1534
- * @param {Vector2} posEnd
1535
- * @param {EngineObject} [object]
1536
- * @return {Vector2}
1537
- * @memberof TileCollision */
1538
- export function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
1539
- /**
1540
- * Tile layer data object stores info about how to render a tile
1541
- * @example
1542
- * // create tile layer data with tile index 0 and random orientation and color
1543
- * const tileIndex = 0;
1544
- * const direction = randInt(4)
1545
- * const mirror = randInt(2);
1546
- * const color = randColor();
1547
- * const data = new TileLayerData(tileIndex, direction, mirror, color);
1548
- */
1549
- export class TileLayerData {
1550
- /** Create a tile layer data object, one for each tile in a TileLayer
1551
- * @param {Number} [tile] - The tile to use, untextured if undefined
1552
- * @param {Number} [direction=0] - Integer direction of tile, in 90 degree increments
1553
- * @param {Boolean} [mirror=0] - If the tile should be mirrored along the x axis
1554
- * @param {Color} [color=Color()] - Color of the tile */
1555
- constructor(tile?: number, direction?: number, mirror?: boolean, color?: Color);
1556
- /** @property {Number} - The tile to use, untextured if undefined */
1557
- tile: number;
1558
- /** @property {Number} - Integer direction of tile, in 90 degree increments */
1559
- direction: number;
1560
- /** @property {Boolean} - If the tile should be mirrored along the x axis */
1561
- mirror: boolean;
1562
- /** @property {Color} - Color of the tile */
1563
- color: Color;
1564
- /** Set this tile to clear, it will not be rendered */
1565
- clear(): void;
1566
- }
1567
- /**
1568
- * Tile Layer - cached rendering system for tile layers
1569
- * - Each Tile layer is rendered to an off screen canvas
1570
- * - To allow dynamic modifications, layers are rendered using canvas 2d
1571
- * - Some devices like mobile phones are limited to 4k texture resolution
1572
- * - So with 16x16 tiles this limits layers to 256x256 on mobile devices
1573
- * @extends EngineObject
1574
- * @example
1575
- * // create tile collision and visible tile layer
1576
- * initTileCollision(vec2(200,100));
1577
- * const tileLayer = new TileLayer();
1578
- */
1579
- export class TileLayer extends EngineObject {
1580
- /** Create a tile layer object
1581
- * @param {Vector2} [position=Vector2()] - World space position
1582
- * @param {Vector2} [size=tileCollisionSize] - World space size
1583
- * @param {TileInfo} [tileInfo] - Tile info for layer
1584
- * @param {Vector2} [scale=Vector2(1,1)] - How much to scale this layer when rendered
1585
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1586
- */
1587
- constructor(pos: any, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
1588
- /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1589
- canvas: HTMLCanvasElement;
1590
- /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1591
- context: CanvasRenderingContext2D;
1592
- /** @property {Vector2} - How much to scale this layer when rendered */
1593
- scale: Vector2;
1594
- data: TileLayerData[];
1595
- /** Set data at a given position in the array
1596
- * @param {Vector2} position - Local position in array
1597
- * @param {TileLayerData} data - Data to set
1598
- * @param {Boolean} [redraw=0] - Force the tile to redraw if true */
1599
- setData(layerPos: any, data: TileLayerData, redraw?: boolean): void;
1600
- /** Get data at a given position in the array
1601
- * @param {Vector2} layerPos - Local position in array
1602
- * @return {TileLayerData} */
1603
- getData(layerPos: Vector2): TileLayerData;
1604
- /** Draw all the tile data to an offscreen canvas
1605
- * - This may be slow in some browsers
1606
- */
1607
- redraw(): void;
1608
- /** Call to start the redraw process
1609
- * @param {Boolean} [clear=0] - Should it clear the canvas before drawing */
1610
- redrawStart(clear?: boolean): void;
1611
- savedRenderSettings: (number | HTMLCanvasElement | CanvasRenderingContext2D | Vector2)[];
1612
- /** Call to end the redraw process */
1613
- redrawEnd(): void;
1614
- /** Draw the tile at a given position
1615
- * @param {Vector2} layerPos */
1616
- drawTileData(layerPos: Vector2): void;
1617
- /** Draw all the tiles in this layer */
1618
- drawAllTileData(): void;
1619
- /** Draw directly to the 2D canvas in world space (bipass webgl)
1620
- * @param {Vector2} pos
1621
- * @param {Vector2} size
1622
- * @param {Number} [angle=0]
1623
- * @param {Boolean} [mirror=0]
1624
- * @param {Function} drawFunction */
1625
- drawCanvas2D(pos: Vector2, size: Vector2, angle?: number, mirror?: boolean, drawFunction: Function): void;
1626
- /** Draw a tile directly onto the layer canvas
1627
- * @param {Vector2} pos
1628
- * @param {Vector2} [size=Vector2(1,1)]
1629
- * @param {TileInfo} [tileInfo]
1630
- * @param {Color} [color=Color()]
1631
- * @param {Number} [angle=0]
1632
- * @param {Boolean} [mirror=0] */
1633
- drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
1634
- /** Draw a rectangle directly onto the layer canvas
1635
- * @param {Vector2} pos
1636
- * @param {Vector2} [size=Vector2(1,1)]
1637
- * @param {Color} [color=Color()]
1638
- * @param {Number} [angle=0] */
1639
- drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
1640
- }
1641
- /**
1642
- * LittleJS Particle System
1643
- */
1644
- /**
1645
- * Particle Emitter - Spawns particles with the given settings
1646
- * @extends EngineObject
1647
- * @example
1648
- * // create a particle emitter
1649
- * let pos = vec2(2,3);
1650
- * let particleEmiter = new ParticleEmitter
1651
- * (
1652
- * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
1653
- * tile(0, 16), // tileInfo
1654
- * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
1655
- * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
1656
- * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
1657
- * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
1658
- * .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
1659
- * );
1660
- */
1661
- export class ParticleEmitter extends EngineObject {
1662
- /** Create a particle system with the given settings
1663
- * @param {Vector2} position - World space position of the emitter
1664
- * @param {Number} [angle=0] - Angle to emit the particles
1665
- * @param {Number} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
1666
- * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
1667
- * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
1668
- * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
1669
- * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
1670
- * @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
1671
- * @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
1672
- * @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
1673
- * @param {Color} [colorEndB=Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
1674
- * @param {Number} [particleTime=.5] - How long particles live
1675
- * @param {Number} [sizeStart=.1] - How big are particles at start
1676
- * @param {Number} [sizeEnd=1] - How big are particles at end
1677
- * @param {Number} [speed=.1] - How fast are particles when spawned
1678
- * @param {Number} [angleSpeed=.05] - How fast are particles rotating
1679
- * @param {Number} [damping=1] - How much to dampen particle speed
1680
- * @param {Number} [angleDamping=1] - How much to dampen particle angular speed
1681
- * @param {Number} [gravityScale=0] - How much does gravity effect particles
1682
- * @param {Number} [particleConeAngle=PI] - Cone for start particle angle
1683
- * @param {Number} [fadeRate=.1] - How quick to fade in particles at start/end in percent of life
1684
- * @param {Number} [randomness=.2] - Apply extra randomness percent
1685
- * @param {Boolean} [collideTiles=0] - Do particles collide against tiles
1686
- * @param {Boolean} [additive=0] - Should particles use addtive blend
1687
- * @param {Boolean} [randomColorLinear=1] - Should color be randomized linearly or across each component
1688
- * @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
1689
- * @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
1690
- */
1691
- constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileInfo?: TileInfo, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
1692
- /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
1693
- emitSize: number;
1694
- /** @property {Number} - How long to stay alive (0 is forever) */
1695
- emitTime: number;
1696
- /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
1697
- emitRate: number;
1698
- /** @property {Number} - Local angle to apply velocity to particles from emitter */
1699
- emitConeAngle: number;
1700
- /** @property {Color} - Color at start of life 1, randomized between start colors */
1701
- colorStartA: Color;
1702
- /** @property {Color} - Color at start of life 2, randomized between start colors */
1703
- colorStartB: Color;
1704
- /** @property {Color} - Color at end of life 1, randomized between end colors */
1705
- colorEndA: Color;
1706
- /** @property {Color} - Color at end of life 2, randomized between end colors */
1707
- colorEndB: Color;
1708
- /** @property {Boolean} - Should color be randomized linearly or across each component */
1709
- randomColorLinear: boolean;
1710
- /** @property {Number} - How long particles live */
1711
- particleTime: number;
1712
- /** @property {Number} - How big are particles at start */
1713
- sizeStart: number;
1714
- /** @property {Number} - How big are particles at end */
1715
- sizeEnd: number;
1716
- /** @property {Number} - How fast are particles when spawned */
1717
- speed: number;
1718
- /** @property {Number} - How fast are particles rotating */
1719
- angleSpeed: number;
1720
- /** @property {Number} - Cone for start particle angle */
1721
- particleConeAngle: number;
1722
- /** @property {Number} - How quick to fade in particles at start/end in percent of life */
1723
- fadeRate: number;
1724
- /** @property {Number} - Apply extra randomness percent */
1725
- randomness: number;
1726
- /** @property {Number} - Do particles collide against tiles */
1727
- collideTiles: boolean;
1728
- /** @property {Number} - Should particles use addtive blend */
1729
- additive: boolean;
1730
- /** @property {Boolean} - Should it be in local space of emitter */
1731
- localSpace: boolean;
1732
- /** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
1733
- trailScale: number;
1734
- emitTimeBuffer: number;
1735
- /** Spawn one particle
1736
- * @return {Particle} */
1737
- emitParticle(): Particle;
1738
- }
1739
- /**
1740
- * Particle Object - Created automatically by Particle Emitters
1741
- * @extends EngineObject
1742
- */
1743
- export class Particle extends EngineObject {
1744
- /**
1745
- * Create a particle with the given settings
1746
- * @param {Vector2} position - World space position of the particle
1747
- * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
1748
- * @param {Number} [angle=0] - Angle to rotate the particle
1749
- */
1750
- constructor(pos: any, tileInfo?: TileInfo, angle?: number);
1751
- }
1752
- /**
1753
- * LittleJS Medal System
1754
- * - Tracks and displays medals
1755
- * - Saves medals to local storage
1756
- * - Newgrounds integration
1757
- * @namespace Medals
1758
- */
1759
- /** List of all medals
1760
- * @type {Array}
1761
- * @memberof Medals */
1762
- export const medals: any[];
1763
- /** Set to stop medals from being unlockable (like if cheats are enabled)
1764
- * @type {Boolean}
1765
- * @default 0
1766
- * @memberof Settings */
1767
- export let medalsPreventUnlock: boolean;
1768
- /** Initialize medals with a save name used for storage
1769
- * - Call this after creating all medals
1770
- * - Checks if medals are unlocked
1771
- * @param {String} saveName
1772
- * @memberof Medals */
1773
- export function medalsInit(saveName: string): void;
1774
- /** This can used to enable Newgrounds functionality
1775
- * @param {Number} app_id - The newgrounds App ID
1776
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
1777
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
1778
- * @memberof Medals */
1779
- export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
1780
- /**
1781
- * Medal - Tracks an unlockable medal
1782
- * @example
1783
- * // create a medal
1784
- * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
1785
- *
1786
- * // initialize medals
1787
- * medalsInit('Example Game');
1788
- *
1789
- * // unlock the medal
1790
- * medal_example.unlock();
1791
- */
1792
- export class Medal {
1793
- /** Create a medal object and adds it to the list of medals
1794
- * @param {Number} id - The unique identifier of the medal
1795
- * @param {String} name - Name of the medal
1796
- * @param {String} [description] - Description of the medal
1797
- * @param {String} [icon='🏆'] - Icon for the medal
1798
- * @param {String} [src] - Image location for the medal
1799
- */
1800
- constructor(id: number, name: string, description?: string, icon?: string, src?: string);
1801
- id: number;
1802
- name: string;
1803
- description: string;
1804
- icon: string;
1805
- image: HTMLImageElement;
1806
- /** Unlocks a medal if not already unlocked */
1807
- unlock(): void;
1808
- unlocked: number;
1809
- /** Render a medal
1810
- * @param {Number} [hidePercent=0] - How much to slide the medal off screen
1811
- */
1812
- render(hidePercent?: number): void;
1813
- /** Render the icon for a medal
1814
- * @param {Number} x - Screen space X position
1815
- * @param {Number} y - Screen space Y position
1816
- * @param {Number} [size=medalDisplayIconSize] - Screen space size
1817
- */
1818
- renderIcon(pos: any, size?: number): void;
1819
- storageKey(): string;
1820
- }
1821
- /**
1822
- * Newgrounds API wrapper object
1823
- * @example
1824
- * // create a newgrounds object, replace the app id with your own
1825
- * const app_id = '53123:1ZuSTQ9l';
1826
- * newgrounds = new Newgrounds(app_id);
1827
- */
1828
- export class Newgrounds {
1829
- /** Create a newgrounds object
1830
- * @param {Number} app_id - The newgrounds App ID
1831
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
1832
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
1833
- constructor(app_id: number, cipher?: string, cryptoJS?: any);
1834
- app_id: number;
1835
- cipher: string;
1836
- cryptoJS: any;
1837
- host: string;
1838
- session_id: string;
1839
- medals: any;
1840
- scoreboards: any;
1841
- /** Send message to unlock a medal by id
1842
- * @param {Number} id - The medal id */
1843
- unlockMedal(id: number): any;
1844
- /** Send message to post score
1845
- * @param {Number} id - The scoreboard id
1846
- * @param {Number} value - The score value */
1847
- postScore(id: number, value: number): any;
1848
- /** Get scores from a scoreboard
1849
- * @param {Number} id - The scoreboard id
1850
- * @param {String} [user=0] - A user's id or name
1851
- * @param {Number} [social=0] - If true, only social scores will be loaded
1852
- * @param {Number} [skip=0] - Number of scores to skip before start
1853
- * @param {Number} [limit=10] - Number of scores to include in the list
1854
- * @return {Object} - The response JSON object
1855
- */
1856
- getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
1857
- /** Send message to log a view */
1858
- logView(): any;
1859
- /** Send a message to call a component of the Newgrounds API
1860
- * @param {String} component - Name of the component
1861
- * @param {Object} [parameters=0] - Parameters to use for call
1862
- * @param {Boolean} [async=0] - If true, don't wait for response before continuing (avoid stall)
1863
- * @return {Object} - The response JSON object
1864
- */
1865
- call(component: string, parameters?: any, async?: boolean): any;
1866
- }
1867
- /**
1868
- * LittleJS WebGL Interface
1869
- * - All webgl used by the engine is wrapped up here
1870
- * - For normal stuff you won't need to see or call anything in this file
1871
- * - For advanced stuff there are helper functions to create shaders, textures, etc
1872
- * - Can be disabled with glEnable to revert to 2D canvas rendering
1873
- * - Batches sprite rendering on GPU for incredibly fast performance
1874
- * - Sprite transform math is done in the shader where possible
1875
- * - Supports shadertoy style post processing shaders
1876
- * @namespace WebGL
1877
- */
1878
- /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1879
- * @type {HTMLCanvasElement}
1880
- * @memberof WebGL */
1881
- export let glCanvas: HTMLCanvasElement;
1882
- /** 2d context for glCanvas
1883
- * @type {WebGLRenderingContext}
1884
- * @memberof WebGL */
1885
- export let glContext: WebGLRenderingContext;
1886
- /** Set the WebGl blend mode, normally you should call setBlendMode instead
1887
- * @param {Boolean} [additive=0]
1888
- * @memberof WebGL */
1889
- export function glSetBlendMode(additive?: boolean): void;
1890
- /** Set the WebGl texture, called automatically if using multiple textures
1891
- * - This may also flush the gl buffer resulting in more draw calls and worse performance
1892
- * @param {WebGLTexture} texture
1893
- * @memberof WebGL */
1894
- export function glSetTexture(texture: WebGLTexture): void;
1895
- /** Compile WebGL shader of the given type, will throw errors if in debug mode
1896
- * @param {String} source
1897
- * @param type
1898
- * @return {WebGLShader}
1899
- * @memberof WebGL */
1900
- export function glCompileShader(source: string, type: any): WebGLShader;
1901
- /** Create WebGL program with given shaders
1902
- * @param {WebGLShader} vsSource
1903
- * @param {WebGLShader} fsSource
1904
- * @return {WebGLProgram}
1905
- * @memberof WebGL */
1906
- export function glCreateProgram(vsSource: WebGLShader, fsSource: WebGLShader): WebGLProgram;
1907
- /** Create WebGL texture from an image and set the texture settings
1908
- * @param {Image} image
1909
- * @return {WebGLTexture}
1910
- * @memberof WebGL */
1911
- export function glCreateTexture(image: new (width?: number, height?: number) => HTMLImageElement): WebGLTexture;
1912
- /** Set up a post processing shader
1913
- * @param {String} shaderCode
1914
- * @param {Boolean} includeOverlay
1915
- * @memberof WebGL */
1916
- export function glInitPostProcess(shaderCode: string, includeOverlay: boolean): void;
1917
- /**
1918
- * LittleJS - The Tiny JavaScript Game Engine That Can!
1919
- * MIT License - Copyright 2021 Frank Force
1920
- *
1921
- * Engine Features
1922
- * - Object oriented system with base class engine object
1923
- * - Base class object handles update, physics, collision, rendering, etc
1924
- * - Engine helper classes and functions like Vector2, Color, and Timer
1925
- * - Super fast rendering system for tile sheets
1926
- * - Sound effects audio with zzfx and music with zzfxm
1927
- * - Input processing system with gamepad and touchscreen support
1928
- * - Tile layer rendering and collision system
1929
- * - Particle effect system
1930
- * - Medal system tracks and displays achievements
1931
- * - Debug tools and debug rendering system
1932
- * - Post processing effects
1933
- * - Call engineInit() to start it up!
1934
- * @namespace Engine
1935
- */
1936
- /** Name of engine
1937
- * @type {String}
1938
- * @default
1939
- * @memberof Engine */
1940
- export const engineName: string;
1941
- /** Version of engine
1942
- * @type {String}
1943
- * @default
1944
- * @memberof Engine */
1945
- export const engineVersion: string;
1946
- /** Frames per second to update objects
1947
- * @type {Number}
1948
- * @default
1949
- * @memberof Engine */
1950
- export const frameRate: number;
1951
- /** How many seconds each frame lasts, engine uses a fixed time step
1952
- * @type {Number}
1953
- * @default 1/60
1954
- * @memberof Engine */
1955
- export const timeDelta: number;
1956
- /** Array containing all engine objects
1957
- * @type {Array}
1958
- * @memberof Engine */
1959
- export let engineObjects: any[];
1960
- /** Current update frame, used to calculate time
1961
- * @type {Number}
1962
- * @memberof Engine */
1963
- export let frame: number;
1964
- /** Current engine time since start in seconds, derived from frame
1965
- * @type {Number}
1966
- * @memberof Engine */
1967
- export let time: number;
1968
- /** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
1969
- * @type {Number}
1970
- * @memberof Engine */
1971
- export let timeReal: number;
1972
- /** Is the game paused? Causes time and objects to not be updated
1973
- * @type {Boolean}
1974
- * @default 0
1975
- * @memberof Engine */
1976
- export let paused: boolean;
1977
- /** Set if game is paused
1978
- * @param {Boolean} paused
1979
- * @memberof Engine */
1980
- export function setPaused(_paused: any): void;
1981
- /** Start up LittleJS engine with your callback functions
1982
- * @param {Function} gameInit - Called once after the engine starts up, setup the game
1983
- * @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
1984
- * @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
1985
- * @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
1986
- * @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
1987
- * @param {String} [imageSources='tiles.png'] - Image to load
1988
- * @memberof Engine */
1989
- export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: string): void;
1990
- /** Update each engine object, remove destroyed objects, and update time
1991
- * @memberof Engine */
1992
- export function engineObjectsUpdate(): void;
1993
- /** Destroy and remove all objects
1994
- * @memberof Engine */
1995
- export function engineObjectsDestroy(): void;
1996
- /** Triggers a callback for each object within a given area
1997
- * @param {Vector2} [pos] - Center of test area
1998
- * @param {Number} [size] - Radius of circle if float, rectangle size if Vector2
1999
- * @param {Function} [callbackFunction] - Calls this function on every object that passes the test
2000
- * @param {Array} [objects=engineObjects] - List of objects to check
2001
- * @memberof Engine */
2002
- export function engineObjectsCallback(pos?: Vector2, size?: number, callbackFunction?: Function, objects?: any[]): void;
2003
- }