q5play 4.1.2 → 4.2.0

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.
Files changed (5) hide show
  1. package/package.json +1 -1
  2. package/py.typed +0 -0
  3. package/q5play.d.ts +1369 -144
  4. package/q5play.js +466 -125
  5. package/q5play.pyi +5007 -0
package/q5play.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ /** @module q5play */
2
+
1
3
  import 'q5';
2
4
 
5
+ // only used to build the q5play.org/docs
6
+ // import type { b2BodyId, b2WorldId, b2JointId } from './Box2D.deluxe.d.ts';
7
+
3
8
  declare global {
4
9
  class Q5Play {
5
10
  /**
@@ -13,6 +18,7 @@ declare global {
13
18
  sprites: {
14
19
  [key: number]: Sprite;
15
20
  };
21
+
16
22
  /**
17
23
  * Contains all the groups in the sketch.
18
24
  *
@@ -21,14 +27,17 @@ declare global {
21
27
  groups: {
22
28
  [key: number]: Group;
23
29
  };
30
+
24
31
  groupsCreated: number;
25
32
  spritesCreated: number;
26
33
  spritesDrawn: number;
34
+
27
35
  /**
28
36
  * The default color palette, at index 0 of this array,
29
37
  * has all the letters of the English alphabet mapped to colors.
30
38
  */
31
39
  palettes: any[];
40
+
32
41
  /**
33
42
  * Friendly rounding makes some Sprite getters return nice rounded numbers
34
43
  * if a decimal value is within linear slop range (+/-0.005) or
@@ -41,13 +50,16 @@ declare global {
41
50
  * @default true
42
51
  */
43
52
  friendlyRounding: boolean;
53
+
44
54
  /**
45
55
  * Information about the operating system being used.
46
56
  */
47
57
  os: {};
58
+
48
59
  context: string;
49
60
  hasMouse: boolean;
50
61
  standardizeKeyboard: boolean;
62
+
51
63
  /**
52
64
  * Displays the version of q5play being used,
53
65
  * the number of sprites being drawn
@@ -70,15 +82,18 @@ declare global {
70
82
  * @default false
71
83
  */
72
84
  renderStats: boolean;
85
+
73
86
  /**
74
87
  * "Made with q5play" [splash screen](https://en.wikipedia.org/wiki/Splash_screen) displayed during
75
88
  * initial page load by default.
76
89
  */
77
90
  splashScreen(): Promise<void>;
91
+
78
92
  /**
79
93
  * Runs automatically before each draw function call.
80
94
  */
81
95
  update(): void;
96
+
82
97
  /**
83
98
  * Runs automatically after each draw function call.
84
99
  */
@@ -120,6 +135,10 @@ declare global {
120
135
  friction: number;
121
136
  bounciness: number;
122
137
  density: number;
138
+ get rollingResistance(): number;
139
+ set rollingResistance(val: number);
140
+ get surfaceSpeed(): number;
141
+ set surfaceSpeed(val: number);
123
142
  }
124
143
 
125
144
  /**
@@ -136,45 +155,53 @@ declare global {
136
155
  }
137
156
 
138
157
  /**
139
- * Visual objects store images and animations that can be displayed
140
- * with respect to the camera.
158
+ * A Visual object stores an image or animation(s)
159
+ * which can be displayed with respect to the camera.
141
160
  */
142
161
  class Visual {
143
162
  /**
144
163
  * Horizontal position of the visual.
145
164
  */
146
165
  x: number;
166
+
147
167
  /**
148
168
  * Vertical position of the visual.
149
169
  */
150
170
  y: number;
171
+
151
172
  /**
152
173
  * Horizontal velocity of the visual.
153
174
  */
154
175
  vx: number;
176
+
155
177
  /**
156
178
  * Vertical velocity of the visual.
157
179
  */
158
180
  vy: number;
181
+
159
182
  /**
160
183
  * Draws the visual on the canvas.
161
184
  */
162
185
  draw(): void;
186
+
163
187
  /**
164
188
  * Current image or frame of animation being displayed.
165
189
  */
166
190
  get img(): Q5.Image;
167
- set img(image: Q5.Image);
191
+ set img(image: string | Q5.Image);
192
+
168
193
  /**
169
194
  * Current animation.
170
195
  */
171
196
  get ani(): Ani;
172
197
  set ani(val: Ani);
198
+
173
199
  /**
174
200
  * Stores animations.
175
201
  * Keys are the animation label, values are Ani objects
176
202
  */
177
203
  get anis(): Anis;
204
+
178
205
  /**
179
206
  * Adds an animation to the Sprite or Visual.
180
207
  *
@@ -183,6 +210,26 @@ declare global {
183
210
  * @returns A promise that fulfills when the animation is loaded
184
211
  */
185
212
  addAni(spriteSheetURL: string, frameCount: number): Promise<void>;
213
+
214
+ /**
215
+ * Add multiple animations to the Sprite or Visual.
216
+ *
217
+ * @param atlases an object with animation names as keys and
218
+ * an animation or animation atlas as values
219
+ * @returns A promise that fulfills when the animations are loaded
220
+ */
221
+ addAnis(atlases: {}): Promise<void>;
222
+
223
+ /**
224
+ * Add multiple animations to the Sprite or Visual.
225
+ *
226
+ * @param spriteSheetURL the URL of the sprite sheet image
227
+ * @param atlases an object with animation names as keys and
228
+ * an animation or animation atlas as values
229
+ * @returns A promise that fulfills when the animations are loaded
230
+ */
231
+ addAnis(spriteSheetURL: string, atlases: {}): Promise<void>;
232
+
186
233
  /**
187
234
  * Add multiple animations to the Sprite or Visual.
188
235
  *
@@ -192,7 +239,8 @@ declare global {
192
239
  * an animation or animation atlas as values
193
240
  * @returns A promise that fulfills when the animations are loaded
194
241
  */
195
- addAnis(spriteSheetURL?: string, frameSize?: string, atlases: {}): Promise<void>;
242
+ addAnis(spriteSheetURL: string, frameSize: string, atlases: {}): Promise<void>;
243
+
196
244
  /**
197
245
  * Changes the sprite's animation. Use `addAni` to define the
198
246
  * animation(s) first.
@@ -200,6 +248,7 @@ declare global {
200
248
  * @param name the name of the animation to switch to
201
249
  */
202
250
  changeAni(name: string): void;
251
+
203
252
  /**
204
253
  * Plays an animation.
205
254
  *
@@ -212,6 +261,7 @@ declare global {
212
261
  * @returns A promise that fulfills when the animation completes
213
262
  */
214
263
  playAni(name: string): Promise<void>;
264
+
215
265
  /**
216
266
  * Plays a sequence of animations.
217
267
  *
@@ -237,6 +287,9 @@ declare global {
237
287
  const KINEMATIC: 'kinematic';
238
288
  const KIN: 'kinematic';
239
289
 
290
+ /**
291
+ * A Sprite has a Box2D physics body with a collider (by default), which can interact with other sprites in the physics simulation.
292
+ */
240
293
  class Sprite extends Visual {
241
294
  /**
242
295
  * Creates a new sprite.
@@ -252,9 +305,131 @@ declare global {
252
305
  * STATIC or KINEMATIC
253
306
  */
254
307
  constructor(x?: number, y?: number, w?: number, h?: number, physicsType?: string);
308
+
309
+ /**
310
+ * Creates a new sprite.
311
+ * @param x horizontal position
312
+ * @param y vertical position
313
+ * @param w width of the collider
314
+ * @param h height of the collider
315
+ * @param roundedRadius corner radius for a rounded box collider
316
+ * @param physicsType physics type is DYNAMIC by default, can be
317
+ * STATIC or KINEMATIC
318
+ */
319
+ constructor(x?: number, y?: number, w?: number, h?: number, roundedRadius?: number, physicsType?: string);
320
+
321
+ /**
322
+ * Creates a new sprite with a circle collider.
323
+ * @param x horizontal position
324
+ * @param y vertical position
325
+ * @param d diameter of the circle collider
326
+ * @param physicsType physics type is DYNAMIC by default, can be
327
+ * STATIC or KINEMATIC
328
+ */
329
+ constructor(x: number, y: number, d: number, physicsType?: string);
330
+
331
+ /**
332
+ * Creates a new sprite with a capsule collider.
333
+ * @param points array of two [x, y] points defining the capsule's endpoints
334
+ * @param roundedRadius the radius of the capsule's rounded ends
335
+ * @param physicsType physics type is DYNAMIC by default, can be
336
+ * STATIC or KINEMATIC
337
+ */
338
+ constructor(points: [number, number][], roundedRadius: number, physicsType?: string);
339
+
340
+ /**
341
+ * Creates a new sprite with a chain or polygon collider defined by absolute vertex positions.
342
+ * If the first and last vertex are the same and the shape is convex, it becomes a polygon.
343
+ * @param vertices array of [x, y] vertex positions
344
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
345
+ */
346
+ constructor(vertices: [number, number][], physicsType?: string);
347
+
348
+ /**
349
+ * Creates a new sprite with a chain collider defined by relative vertex offsets from the sprite's position.
350
+ * @param x horizontal position
351
+ * @param y vertical position
352
+ * @param vertices array of relative [x, y] vertex offsets
353
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
354
+ */
355
+ constructor(x: number, y: number, vertices: [number, number][], physicsType?: string);
356
+
357
+ /**
358
+ * Creates a new sprite with a chain collider defined by alternating segment lengths and angles.
359
+ * Each angle is relative to the previous segment's angle.
360
+ * If the last value is 5, the chain is closed into a loop.
361
+ * @param x horizontal position
362
+ * @param y vertical position
363
+ * @param distAngles alternating segment lengths and relative angles; append 5 to close the chain
364
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
365
+ */
366
+ constructor(x: number, y: number, distAngles: number[], physicsType?: string);
367
+
368
+ /**
369
+ * Creates a new sprite with a rounded chain collider defined by alternating segment lengths and angles.
370
+ * Each angle is relative to the previous segment's angle.
371
+ * If the last value is 5, the chain is closed into a loop.
372
+ * @param x horizontal position
373
+ * @param y vertical position
374
+ * @param distAngles alternating segment lengths and relative angles; append 5 to close the chain
375
+ * @param roundedRadius the rounded radius of the chain's segments
376
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
377
+ */
378
+ constructor(x: number, y: number, distAngles: number[], roundedRadius: number, physicsType?: string);
379
+
380
+ /**
381
+ * Creates a new sprite with a regular polygon collider.
382
+ * @param x horizontal position
383
+ * @param y vertical position
384
+ * @param sideLength the length of each side of the polygon
385
+ * @param polygonName 'triangle', 'square', 'pentagon', 'hexagon', 'septagon', or 'octagon'
386
+ * @param roundedRadius corner radius for a rounded polygon
387
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
388
+ */
389
+ constructor(
390
+ x: number,
391
+ y: number,
392
+ sideLength: number,
393
+ polygonName: string,
394
+ roundedRadius?: number,
395
+ physicsType?: string
396
+ );
397
+
398
+ constructor(ani: string | Ani | Q5.Image, x?: number, y?: number, w?: number, h?: number, physicsType?: string);
399
+ constructor(
400
+ ani: string | Ani | Q5.Image,
401
+ x?: number,
402
+ y?: number,
403
+ w?: number,
404
+ h?: number,
405
+ roundedRadius?: number,
406
+ physicsType?: string
407
+ );
408
+ constructor(ani: string | Ani | Q5.Image, x: number, y: number, d: number, physicsType?: string);
409
+ constructor(ani: string | Ani | Q5.Image, points: [number, number][], roundedRadius: number, physicsType?: string);
410
+ constructor(ani: string | Ani | Q5.Image, vertices: [number, number][], physicsType?: string);
411
+ constructor(ani: string | Ani | Q5.Image, x: number, y: number, vertices: [number, number][], physicsType?: string);
412
+ constructor(ani: string | Ani | Q5.Image, x: number, y: number, distAngles: number[], physicsType?: string);
413
+ constructor(
414
+ ani: string | Ani | Q5.Image,
415
+ x: number,
416
+ y: number,
417
+ distAngles: number[],
418
+ roundedRadius: number,
419
+ physicsType?: string
420
+ );
421
+ constructor(
422
+ ani: string | Ani | Q5.Image,
423
+ x: number,
424
+ y: number,
425
+ sideLength: number,
426
+ polygonName: string,
427
+ roundedRadius?: number,
428
+ physicsType?: string
429
+ );
430
+
255
431
  /**
256
432
  * Creates a new sprite with an overlap sensor instead of a collider.
257
- *
258
433
  * @param x horizontal position
259
434
  * @param y vertical position
260
435
  * @param w width of the sensor
@@ -263,6 +438,160 @@ declare global {
263
438
  * STATIC or KINEMATIC
264
439
  */
265
440
  static withSensor(x?: number, y?: number, w?: number, h?: number, physicsType?: string): Sprite;
441
+
442
+ /**
443
+ * Creates a new sprite with an overlap sensor instead of a collider.
444
+ * @param x horizontal position
445
+ * @param y vertical position
446
+ * @param w width of the sensor
447
+ * @param h height of the sensor
448
+ * @param roundedRadius corner radius for a rounded box sensor
449
+ * @param physicsType physics type is DYNAMIC by default, can be
450
+ * STATIC or KINEMATIC
451
+ */
452
+ static withSensor(
453
+ x?: number,
454
+ y?: number,
455
+ w?: number,
456
+ h?: number,
457
+ roundedRadius?: number,
458
+ physicsType?: string
459
+ ): Sprite;
460
+
461
+ /**
462
+ * Creates a new sprite with a circle overlap sensor.
463
+ * @param x horizontal position
464
+ * @param y vertical position
465
+ * @param d diameter of the circle sensor
466
+ * @param physicsType physics type is DYNAMIC by default, can be
467
+ * STATIC or KINEMATIC
468
+ */
469
+ static withSensor(x: number, y: number, d: number, physicsType?: string): Sprite;
470
+
471
+ /**
472
+ * Creates a new sprite with a capsule overlap sensor.
473
+ * @param points array of two [x, y] points defining the capsule's endpoints
474
+ * @param roundedRadius the radius of the capsule's rounded ends
475
+ * @param physicsType physics type is DYNAMIC by default, can be
476
+ * STATIC or KINEMATIC
477
+ */
478
+ static withSensor(points: [number, number][], roundedRadius: number, physicsType?: string): Sprite;
479
+
480
+ /**
481
+ * Creates a new sprite with a chain overlap sensor defined by absolute vertex positions.
482
+ * If the first and last vertex are the same and the shape is convex, it becomes a polygon sensor.
483
+ * @param vertices array of [x, y] vertex positions
484
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
485
+ */
486
+ static withSensor(vertices: [number, number][], physicsType?: string): Sprite;
487
+
488
+ /**
489
+ * Creates a new sprite with a chain overlap sensor defined by relative vertex offsets from the sprite's position.
490
+ * @param x horizontal position
491
+ * @param y vertical position
492
+ * @param vertices array of relative [x, y] vertex offsets
493
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
494
+ */
495
+ static withSensor(x: number, y: number, vertices: [number, number][], physicsType?: string): Sprite;
496
+
497
+ /**
498
+ * Creates a new sprite with a chain overlap sensor defined by alternating segment lengths and angles.
499
+ * Each angle is relative to the previous segment's angle.
500
+ * If the last value is 5, the chain is closed into a loop.
501
+ * @param x horizontal position
502
+ * @param y vertical position
503
+ * @param distAngles alternating segment lengths and relative angles; append 5 to close the chain
504
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
505
+ */
506
+ static withSensor(x: number, y: number, distAngles: number[], physicsType?: string): Sprite;
507
+
508
+ /**
509
+ * Creates a new sprite with a rounded chain overlap sensor defined by alternating segment lengths and angles.
510
+ * Each angle is relative to the previous segment's angle.
511
+ * If the last value is 5, the chain is closed into a loop.
512
+ * @param x horizontal position
513
+ * @param y vertical position
514
+ * @param distAngles alternating segment lengths and relative angles; append 5 to close the chain
515
+ * @param roundedRadius the rounded radius of the chain's segments
516
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
517
+ */
518
+ static withSensor(x: number, y: number, distAngles: number[], roundedRadius: number, physicsType?: string): Sprite;
519
+
520
+ /**
521
+ * Creates a new sprite with a regular polygon overlap sensor.
522
+ * @param x horizontal position
523
+ * @param y vertical position
524
+ * @param sideLength the length of each side of the polygon
525
+ * @param polygonName 'triangle', 'square', 'pentagon', 'hexagon', 'septagon', or 'octagon'
526
+ * @param roundedRadius corner radius for a rounded polygon
527
+ * @param physicsType physics type is DYNAMIC by default, can be STATIC or KINEMATIC
528
+ */
529
+ static withSensor(
530
+ x: number,
531
+ y: number,
532
+ sideLength: number,
533
+ polygonName: string,
534
+ roundedRadius?: number,
535
+ physicsType?: string
536
+ ): Sprite;
537
+
538
+ static withSensor(
539
+ ani: string | Ani | Q5.Image,
540
+ x?: number,
541
+ y?: number,
542
+ w?: number,
543
+ h?: number,
544
+ physicsType?: string
545
+ ): Sprite;
546
+ static withSensor(
547
+ ani: string | Ani | Q5.Image,
548
+ x?: number,
549
+ y?: number,
550
+ w?: number,
551
+ h?: number,
552
+ roundedRadius?: number,
553
+ physicsType?: string
554
+ ): Sprite;
555
+ static withSensor(ani: string | Ani | Q5.Image, x: number, y: number, d: number, physicsType?: string): Sprite;
556
+ static withSensor(
557
+ ani: string | Ani | Q5.Image,
558
+ points: [number, number][],
559
+ roundedRadius: number,
560
+ physicsType?: string
561
+ ): Sprite;
562
+ static withSensor(ani: string | Ani | Q5.Image, vertices: [number, number][], physicsType?: string): Sprite;
563
+ static withSensor(
564
+ ani: string | Ani | Q5.Image,
565
+ x: number,
566
+ y: number,
567
+ vertices: [number, number][],
568
+ physicsType?: string
569
+ ): Sprite;
570
+ static withSensor(
571
+ ani: string | Ani | Q5.Image,
572
+ x: number,
573
+ y: number,
574
+ distAngles: number[],
575
+ physicsType?: string
576
+ ): Sprite;
577
+ static withSensor(
578
+ ani: string | Ani | Q5.Image,
579
+ x: number,
580
+ y: number,
581
+ distAngles: number[],
582
+ roundedRadius: number,
583
+ physicsType?: string
584
+ ): Sprite;
585
+ static withSensor(
586
+ ani: string | Ani | Q5.Image,
587
+ x: number,
588
+ y: number,
589
+ sideLength: number,
590
+ polygonName: string,
591
+ roundedRadius?: number,
592
+ physicsType?: string
593
+ ): Sprite;
594
+
266
595
  /**
267
596
  * The physics type of the sprite, which determines how it interacts with
268
597
  * other sprites in the physics simulation.
@@ -272,6 +601,7 @@ declare global {
272
601
  */
273
602
  get physics(): string;
274
603
  set physics(val: string);
604
+
275
605
  /**
276
606
  * The physics type of the sprite, which determines how it interacts with
277
607
  * other sprites in the physics simulation.
@@ -281,40 +611,53 @@ declare global {
281
611
  */
282
612
  get physicsType(): string;
283
613
  set physicsType(val: string);
614
+
284
615
  /**
285
616
  * If true, the sprite's physics body is included in the physics simulation.
286
617
  * @default true
287
618
  */
288
619
  get physicsEnabled(): boolean;
289
620
  set physicsEnabled(val: boolean);
621
+
290
622
  /**
291
623
  * Each sprite has a unique id number. Don't change it!
292
624
  * They are useful for debugging.
293
625
  */
294
626
  idNum: number;
627
+
628
+ /**
629
+ * The Box2D body id for the sprite's physics body. Don't change it!
630
+ */
631
+ bdID: b2BodyId;
632
+
295
633
  /**
296
634
  * Groups the sprite belongs to.
297
635
  * @default [allSprites]
298
636
  */
299
637
  groups: Group[];
638
+
300
639
  /**
301
640
  * Keys are the animation label, values are Ani objects.
302
641
  */
303
642
  animations: Anis;
643
+
304
644
  /**
305
645
  * Array of colliders that are part of the sprite's physics body.
306
646
  */
307
647
  colliders: Collider[];
648
+
308
649
  /**
309
650
  * Array of sensors that are part of the sprite's physics body.
310
651
  * Sensors are used to detect overlaps without causing physical collisions.
311
652
  */
312
653
  sensors: Sensor[];
654
+
313
655
  /**
314
656
  * Joints that the sprite is attached to.
315
657
  * @default []
316
658
  */
317
659
  joints: Joint[];
660
+
318
661
  /**
319
662
  * If set to true, q5play will record all changes to the sprite's
320
663
  * properties in its `mod` array. Intended to be used to enable
@@ -322,6 +665,7 @@ declare global {
322
665
  * @default undefined
323
666
  */
324
667
  watch: boolean;
668
+
325
669
  /**
326
670
  * Modification tracking object.
327
671
  *
@@ -334,39 +678,52 @@ declare global {
334
678
  * to only the sprite properties that have been modified.
335
679
  */
336
680
  mod: {};
681
+
337
682
  /**
338
683
  * The horizontal position of the sprite.
339
684
  */
340
685
  get x(): number;
341
686
  set x(val: number);
687
+
342
688
  /**
343
689
  * The vertical position of the sprite.
344
690
  */
345
691
  get y(): number;
346
692
  set y(val: number);
693
+
347
694
  /**
348
695
  * The width of the sprite.
349
696
  */
350
697
  get w(): number;
351
698
  set w(val: number);
699
+
352
700
  /**
353
701
  * The height of the sprite.
354
702
  */
355
703
  get h(): number;
356
704
  set h(val: number);
705
+
706
+ /**
707
+ * The sprite's x position on the previous frame.
708
+ */
709
+ prevX: number;
710
+
357
711
  /**
358
- * The sprite's position on the previous frame.
712
+ * The sprite's y position on the previous frame.
359
713
  */
360
- prevPos: {};
714
+ prevY: number;
715
+
361
716
  /**
362
717
  * The sprite's rotation on the previous frame.
363
718
  */
364
719
  prevRotation: number;
720
+
365
721
  /**
366
722
  * Text displayed at the center of the sprite.
367
723
  * @default undefined
368
724
  */
369
725
  text: string;
726
+
370
727
  /**
371
728
  * Adds a collider to the sprite's physics body.
372
729
  *
@@ -383,8 +740,10 @@ declare global {
383
740
  * @param offsetY distance from the center of the sprite
384
741
  * @param w width of the collider
385
742
  * @param h height of the collider
743
+ * @param roundedRadius corner radius for a rounded box collider
386
744
  */
387
- addCollider(offsetX: number, offsetY: number, w?: number, h?: number): void;
745
+ addCollider(offsetX: number, offsetY: number, w?: number, h?: number, roundedRadius?: number): void;
746
+
388
747
  /**
389
748
  * Adds an overlap sensor to the sprite's physics body.
390
749
  *
@@ -401,13 +760,16 @@ declare global {
401
760
  * @param offsetY distance from the center of the sprite
402
761
  * @param w width of the collider
403
762
  * @param h height of the collider
763
+ * @param roundedRadius corner radius for a rounded box sensor
404
764
  */
405
- addSensor(offsetX: number, offsetY: number, w?: number, h?: number): void;
765
+ addSensor(offsetX: number, offsetY: number, w?: number, h?: number, roundedRadius?: number): void;
766
+
406
767
  /**
407
768
  * The mass of the sprite's physics body.
408
769
  */
409
770
  get mass(): number;
410
771
  set mass(val: number);
772
+
411
773
  /**
412
774
  * The center of mass of the sprite's physics body, the point at which
413
775
  * the physics body is balanced and rotates around. By default it's the
@@ -415,6 +777,7 @@ declare global {
415
777
  */
416
778
  get centerOfMass(): { x: number; y: number };
417
779
  set centerOfMass(val: { x: number; y: number });
780
+
418
781
  /**
419
782
  * If true, the center of mass of the sprite's physics body is fixed to
420
783
  * the sprite's [x, y] position.
@@ -426,11 +789,13 @@ declare global {
426
789
  */
427
790
  get fixedCenterOfMass(): boolean;
428
791
  set fixedCenterOfMass(val: boolean);
792
+
429
793
  /**
430
794
  * Recalculates the sprite's mass based on its current
431
795
  * density and size.
432
796
  */
433
797
  resetMass(): void;
798
+
434
799
  /**
435
800
  * The angle of the sprite's rotation, not the direction it's moving.
436
801
  *
@@ -440,26 +805,31 @@ declare global {
440
805
  */
441
806
  get rotation(): number;
442
807
  set rotation(val: number);
808
+
443
809
  /**
444
810
  * Removes colliders from the sprite's physics body.
445
811
  */
446
- removeColliders(): void;
812
+ deleteColliders(): void;
813
+
447
814
  /**
448
815
  * Removes overlap sensors from the sprite's physics body.
449
816
  */
450
- removeSensors(): void;
817
+ deleteSensors(): void;
818
+
451
819
  /**
452
820
  * If true, a sprite is updated by q5play before each physics update.
453
821
  * @default true
454
822
  */
455
823
  get autoUpdate(): boolean;
456
824
  set autoUpdate(val: boolean);
825
+
457
826
  /**
458
827
  * If true, a sprite is drawn by q5play after each physics update.
459
828
  * @default true
460
829
  */
461
830
  get autoDraw(): boolean;
462
831
  set autoDraw(val: boolean);
832
+
463
833
  /**
464
834
  * Controls the ability for a sprite to "sleep".
465
835
  *
@@ -470,18 +840,21 @@ declare global {
470
840
  */
471
841
  get allowSleeping(): boolean;
472
842
  set allowSleeping(val: boolean);
843
+
473
844
  /**
474
845
  * The bounciness of the sprite's physics body.
475
846
  * @default 0.2
476
847
  */
477
848
  get bounciness(): number;
478
849
  set bounciness(val: number);
850
+
479
851
  /**
480
852
  * The speed of the sprite's rotation in angles per frame.
481
853
  * @default 0
482
854
  */
483
855
  get rotationSpeed(): number;
484
856
  set rotationSpeed(val: number);
857
+
485
858
  /**
486
859
  * The sprite's current fill color.
487
860
  *
@@ -489,6 +862,7 @@ declare global {
489
862
  */
490
863
  get color(): Q5.Color;
491
864
  set color(val: Q5.Color);
865
+
492
866
  /**
493
867
  * The sprite's current fill colour.
494
868
  *
@@ -496,6 +870,7 @@ declare global {
496
870
  */
497
871
  get colour(): Q5.Color;
498
872
  set colour(val: Q5.Color);
873
+
499
874
  /**
500
875
  * The sprite's current fill color.
501
876
  *
@@ -503,27 +878,32 @@ declare global {
503
878
  */
504
879
  get fill(): Q5.Color;
505
880
  set fill(val: Q5.Color);
881
+
506
882
  /**
507
883
  * The sprite's stroke color.
508
884
  */
509
885
  get stroke(): Q5.Color;
510
886
  set stroke(val: Q5.Color);
887
+
511
888
  /**
512
889
  * The sprite's stroke weight, the thickness of its outline.
513
890
  */
514
891
  get strokeWeight(): number;
515
892
  set strokeWeight(val: number);
893
+
516
894
  /**
517
895
  * The sprite's text fill color. Black by default.
518
896
  * @default black (#000000)
519
897
  */
520
898
  get textFill(): Q5.Color;
521
899
  set textFill(val: Q5.Color);
900
+
522
901
  /**
523
902
  * The sprite's text size, the sketch's current textSize by default.
524
903
  */
525
904
  get textSize(): number;
526
905
  set textSize(val: number);
906
+
527
907
  /**
528
908
  * The sprite's text stroke color.
529
909
  * No stroke by default, does not inherit from the sketch's stroke color.
@@ -531,6 +911,7 @@ declare global {
531
911
  */
532
912
  get textStroke(): Q5.Color;
533
913
  set textStroke(val: Q5.Color);
914
+
534
915
  /**
535
916
  * The sprite's text stroke weight, the thickness of its outline.
536
917
  * No stroke by default, does not inherit from the sketch's stroke weight.
@@ -538,11 +919,13 @@ declare global {
538
919
  */
539
920
  get textStrokeWeight(): number;
540
921
  set textStrokeWeight(val: number);
922
+
541
923
  /**
542
924
  * The tile character that represents the sprite in a tile map.
543
925
  */
544
926
  get tile(): string;
545
927
  set tile(val: string);
928
+
546
929
  /**
547
930
  * A bearing indicates the direction that needs to be followed to
548
931
  * reach a destination.
@@ -553,30 +936,39 @@ declare global {
553
936
  */
554
937
  get bearing(): number;
555
938
  set bearing(val: number);
939
+
556
940
  /**
557
941
  * If true, outlines of the sprite's colliders and sensors will be drawn.
558
942
  * @default false
559
943
  */
560
944
  get debug(): boolean;
561
945
  set debug(val: boolean);
946
+
562
947
  /**
563
948
  * The density of the sprite's physics body.
564
949
  * @default 1
565
950
  */
566
951
  get density(): number;
567
952
  set density(val: number);
953
+
568
954
  /**
569
955
  * The angle of the sprite's movement.
956
+ *
957
+ * Can be set with directional strings like "up", "down", "left", "right",
958
+ * "upRight", "upLeft", "downRight", and "downLeft". The setter's input parser ignores
959
+ * capitalization, spaces, underscores, dashes, and cardinal direction word order.
570
960
  * @default 0 ("right")
571
961
  */
572
962
  get direction(): number;
573
- set direction(val: number);
963
+ set direction(val: number | string);
964
+
574
965
  /**
575
966
  * The amount of resistance a sprite has to being moved.
576
967
  * @default 0
577
968
  */
578
969
  get drag(): number;
579
970
  set drag(val: number);
971
+
580
972
  /**
581
973
  * Displays the sprite.
582
974
  *
@@ -592,6 +984,7 @@ declare global {
592
984
  */
593
985
  get draw(): Function;
594
986
  set draw(val: Function);
987
+
595
988
  /**
596
989
  * The amount the sprite's colliders resist moving
597
990
  * when rubbing against other colliders.
@@ -599,6 +992,7 @@ declare global {
599
992
  */
600
993
  get friction(): number;
601
994
  set friction(val: number);
995
+
602
996
  /**
603
997
  * The sprite's heading. This is a string that can be set to
604
998
  * "up", "down", "left", "right", "upRight", "upLeft", "downRight"
@@ -609,6 +1003,7 @@ declare global {
609
1003
  */
610
1004
  get heading(): string;
611
1005
  set heading(val: string);
1006
+
612
1007
  /**
613
1008
  * Set this to true if the sprite goes really fast to prevent
614
1009
  * inaccurate physics simulation.
@@ -616,6 +1011,7 @@ declare global {
616
1011
  */
617
1012
  get isSuperFast(): boolean;
618
1013
  set isSuperFast(val: boolean);
1014
+
619
1015
  /**
620
1016
  * Sprites with the highest layer value get drawn first.
621
1017
  *
@@ -623,6 +1019,7 @@ declare global {
623
1019
  */
624
1020
  get layer(): number;
625
1021
  set layer(val: number);
1022
+
626
1023
  /**
627
1024
  * When the physics simulation is progressed in `world.physicsUpdate`,
628
1025
  * each sprite's life is decreased by `world.timeScale`.
@@ -633,22 +1030,32 @@ declare global {
633
1030
  */
634
1031
  get life(): number;
635
1032
  set life(val: number);
1033
+
636
1034
  /**
637
1035
  * The sprite's opacity. 0 is transparent, 1 is opaque.
638
1036
  * @default 1
639
1037
  */
640
1038
  get opacity(): number;
641
1039
  set opacity(val: number);
1040
+
1041
+ /**
1042
+ * The sprite's x position on the previous frame.
1043
+ * Alias for sprite.prevX.
1044
+ */
1045
+ get previousX(): number;
1046
+
642
1047
  /**
643
- * Alias for sprite.prevPos
1048
+ * The sprite's y position on the previous frame.
1049
+ * Alias for sprite.prevY.
644
1050
  */
645
- get previousPosition(): any;
646
- set previousPosition(val: any);
1051
+ get previousY(): number;
1052
+
647
1053
  /**
648
- * Alias for sprite.prevRotation
1054
+ * The sprite's rotation on the previous frame.
1055
+ * Alias for sprite.prevRotation.
649
1056
  */
650
1057
  get previousRotation(): number;
651
- set previousRotation(val: number);
1058
+
652
1059
  /**
653
1060
  * If true, q5play will draw sprites at integer pixel precision.
654
1061
  *
@@ -659,12 +1066,14 @@ declare global {
659
1066
  */
660
1067
  get pixelPerfect(): boolean;
661
1068
  set pixelPerfect(val: boolean);
1069
+
662
1070
  /**
663
- * If the sprite has been removed from the world.
1071
+ * If the sprite has been deleted from the world.
664
1072
  * @default false
665
1073
  */
666
- get removed(): boolean;
667
- set removed(val: boolean);
1074
+ get deleted(): boolean;
1075
+ set deleted(val: boolean);
1076
+
668
1077
  /**
669
1078
  * Simulates friction that slows down a sprite rolling on another sprite,
670
1079
  * like a soccer ball rolling to a stop on high grass.
@@ -672,18 +1081,21 @@ declare global {
672
1081
  */
673
1082
  get rollingResistance(): number;
674
1083
  set rollingResistance(val: number);
1084
+
675
1085
  /**
676
1086
  * The amount the sprite resists rotating.
677
1087
  * @default 0
678
1088
  */
679
1089
  get rotationDrag(): number;
680
1090
  set rotationDrag(val: number);
1091
+
681
1092
  /**
682
1093
  * If true, the sprite can not rotate.
683
1094
  * @default false
684
1095
  */
685
1096
  get rotationLock(): boolean;
686
1097
  set rotationLock(val: boolean);
1098
+
687
1099
  /**
688
1100
  * Horizontal and vertical scale of the sprite.
689
1101
  *
@@ -696,12 +1108,14 @@ declare global {
696
1108
  */
697
1109
  get scale(): number | { x: number; y: number };
698
1110
  set scale(val: number | [] | { x: number; y: number });
1111
+
699
1112
  /**
700
1113
  * Scales the the sprite.
701
1114
  * @param x scaleX or uniform scale factor
702
1115
  * @param y scaleY
703
1116
  */
704
1117
  scaleBy(x: number, y?: number): void;
1118
+
705
1119
  /**
706
1120
  * Wake a sprite up or put it to sleep.
707
1121
  *
@@ -712,6 +1126,14 @@ declare global {
712
1126
  */
713
1127
  get sleeping(): boolean;
714
1128
  set sleeping(val: boolean);
1129
+
1130
+ /**
1131
+ * The minimum speed (in m/s) at which the sprite must be moving
1132
+ * before it is considered awake.
1133
+ */
1134
+ get sleepThreshold(): number;
1135
+ set sleepThreshold(val: number);
1136
+
715
1137
  /**
716
1138
  * The sprite's speed.
717
1139
  *
@@ -721,12 +1143,14 @@ declare global {
721
1143
  */
722
1144
  get speed(): number;
723
1145
  set speed(val: number);
1146
+
724
1147
  /**
725
1148
  * Efficiently sets the sprite's speed and direction at the same time.
726
1149
  * @param speed
727
1150
  * @param direction
728
1151
  */
729
1152
  setSpeedAndDirection(speed: number, direction: number): void;
1153
+
730
1154
  /**
731
1155
  * The sprite's speed along the surface of its collider(s),
732
1156
  * like a conveyor belt.
@@ -734,6 +1158,7 @@ declare global {
734
1158
  */
735
1159
  get surfaceSpeed(): number;
736
1160
  set surfaceSpeed(val: number);
1161
+
737
1162
  /**
738
1163
  * Tint color applied to the sprite when drawn.
739
1164
  *
@@ -743,6 +1168,7 @@ declare global {
743
1168
  */
744
1169
  get tint(): Q5.Color;
745
1170
  set tint(val: Q5.Color);
1171
+
746
1172
  /**
747
1173
  * If true the sprite is shown, if set to false the sprite is hidden.
748
1174
  *
@@ -752,71 +1178,91 @@ declare global {
752
1178
  */
753
1179
  get visible(): boolean;
754
1180
  set visible(val: boolean);
1181
+
755
1182
  /**
756
- * The position vector {x, y}
1183
+ * Gets the sprite's position as a readonly object {x, y} which
1184
+ * won't be updated if the sprite moves. Useful for saving
1185
+ * the sprite's position at a specific moment in time.
757
1186
  */
758
- get pos(): Q5.Vector;
759
- set pos(val: [] | { x: number; y: number } | Q5.Vector);
1187
+ get pos(): { x: number; y: number };
1188
+
1189
+ /**
1190
+ * The sprite's position vector.
1191
+ */
1192
+ set pos(val: number[] | { x: number; y: number });
1193
+
760
1194
  /**
761
- * The position vector {x, y}
1195
+ * The sprite's position vector.
762
1196
  */
763
1197
  get position(): Q5.Vector;
764
- set position(val: [] | { x: number; y: number } | Q5.Vector);
1198
+ set position(val: number[] | { x: number; y: number });
1199
+
765
1200
  /**
766
1201
  * The sprite's absolute position on the canvas.
767
1202
  * @readonly
768
1203
  */
769
1204
  get canvasPos(): any;
1205
+
770
1206
  /**
771
1207
  * Half the width of the sprite.
772
1208
  */
773
1209
  get hw(): number;
774
1210
  set hw(val: number);
1211
+
775
1212
  /**
776
1213
  * The width of the sprite.
777
1214
  */
778
1215
  get width(): number;
779
1216
  set width(val: number);
1217
+
780
1218
  /**
781
1219
  * Half the width of the sprite.
782
1220
  */
783
1221
  get halfWidth(): number;
784
1222
  set halfWidth(val: number);
1223
+
785
1224
  /**
786
1225
  * Half the height of the sprite.
787
1226
  */
788
1227
  get hh(): number;
789
1228
  set hh(val: number);
1229
+
790
1230
  /**
791
1231
  * The height of the sprite.
792
1232
  */
793
1233
  get height(): number;
794
1234
  set height(val: number);
1235
+
795
1236
  /**
796
1237
  * Half the height of the sprite.
797
1238
  */
798
1239
  get halfHeight(): number;
799
1240
  set halfHeight(val: number);
1241
+
800
1242
  /**
801
1243
  * The diameter of a circular sprite.
802
1244
  */
803
1245
  get d(): number;
804
1246
  set d(val: number);
1247
+
805
1248
  /**
806
1249
  * The diameter of a circular sprite.
807
1250
  */
808
1251
  get diameter(): number;
809
1252
  set diameter(val: number);
1253
+
810
1254
  /**
811
1255
  * The radius of a circular sprite.
812
1256
  */
813
1257
  get r(): number;
814
1258
  set r(val: number);
1259
+
815
1260
  /**
816
1261
  * The radius of a circular sprite.
817
1262
  */
818
1263
  get radius(): number;
819
1264
  set radius(val: number);
1265
+
820
1266
  /**
821
1267
  * Runs before each physics update by default.
822
1268
  *
@@ -828,45 +1274,93 @@ declare global {
828
1274
  */
829
1275
  get update(): Function;
830
1276
  set update(val: Function);
1277
+
831
1278
  /**
832
1279
  * The sprite's velocity vector {x, y}
833
1280
  * @default {x: 0, y: 0}
834
1281
  */
835
1282
  get vel(): Q5.Vector;
836
1283
  set vel(val: [] | { x: number; y: number } | Q5.Vector);
1284
+
837
1285
  /**
838
1286
  * The sprite's velocity vector {x, y}
839
1287
  * @default {x: 0, y: 0}
840
1288
  */
841
1289
  get velocity(): Q5.Vector;
842
1290
  set velocity(val: [] | { x: number; y: number } | Q5.Vector);
1291
+
843
1292
  /**
844
1293
  * Whether the sprite can be grabbed by a pointer.
845
1294
  */
846
1295
  get grabbable(): boolean;
847
1296
  set grabbable(val: boolean);
1297
+
848
1298
  /**
849
1299
  * A ratio that defines how much the sprite is affected by gravity.
850
1300
  * @default 1
851
1301
  */
852
1302
  get gravityScale(): number;
853
1303
  set gravityScale(val: number);
1304
+
854
1305
  /**
855
1306
  * If this function is given a force amount, the force is applied
856
1307
  * at the angle of the sprite's current bearing. Force can
857
1308
  * also be given as a vector.
858
1309
  *
859
1310
  * @param amount
860
- * @param origin The point the force is applied from, relative to the sprite's center of mass. Accepts a coordinate array or object with x and y properties. If not given, the force is applied at the center of mass.
1311
+ * @param origin The point the force is applied from, relative to the sprite's center of mass. Accepts an object with `x` and `y` properties. If not given, the force is applied at the center of mass.
1312
+ */
1313
+ /**
1314
+ * Applies a force to the sprite.
1315
+ *
1316
+ * - If the first argument is a number, it is treated as a force magnitude
1317
+ * applied at the sprite's current bearing.
1318
+ * - If the first argument is an object, it is treated
1319
+ * as a force vector `{x, y}`.
1320
+ *
1321
+ * The optional `origin` is the point (relative to the sprite's center)
1322
+ * where the force is applied. `origin` accepts an object with `x` and
1323
+ * `y` properties. Arrays are not accepted for input args.
1324
+ */
1325
+ /**
1326
+ * Applies a force magnitude at the sprite's current bearing.
1327
+ * @param amount force magnitude
1328
+ * @param origin point (relative to the sprite) where the force is applied. Accepts an object with `x` and `y` properties.
1329
+ */
1330
+ applyForce(amount: number, origin?: { x: number; y: number }): void;
1331
+
1332
+ /**
1333
+ * Applies a force vector to the sprite.
1334
+ * @param force force vector as an object with `x` and `y` properties or array of [x, y]
1335
+ * @param origin point (relative to the sprite) where the force is applied. Accepts an object with `x` and `y` properties.
861
1336
  */
862
- applyForce(amount: number, origin?: any): void;
1337
+ applyForce(force: { x: number; y: number } | number[], origin?: { x: number; y: number }): void;
1338
+
863
1339
  /**
864
1340
  * Applies a force that's scaled to the sprite's mass.
865
1341
  *
866
1342
  * @param amount
867
- * @param n The point the force is applied from, relative to the sprite's center of mass. Accepts a coordinate array or object with x and y properties. If not given, the force is applied at the center of mass.
1343
+ * @param n The point the force is applied from, relative to the sprite's center of mass. Accepts an object with `x` and `y` properties. If not given, the force is applied at the center of mass.
1344
+ */
1345
+ /**
1346
+ * Applies a force scaled to the sprite's mass.
1347
+ *
1348
+ * See `applyForce` for argument forms. Arrays are not accepted for input args.
868
1349
  */
869
- applyForceScaled(amount: number, origin?: any): void;
1350
+ /**
1351
+ * Applies a force scaled to the sprite's mass using a magnitude.
1352
+ * @param amount force magnitude
1353
+ * @param origin point (relative to the sprite) where the force is applied. Accepts an object with `x` and `y` properties.
1354
+ */
1355
+ applyForceScaled(amount: number, origin?: { x: number; y: number }): void;
1356
+
1357
+ /**
1358
+ * Applies a force scaled to the sprite's mass using a vector.
1359
+ * @param force force vector as an object with `x` and `y` properties
1360
+ * @param origin point (relative to the sprite) where the force is applied. Accepts an object with `x` and `y` properties.
1361
+ */
1362
+ applyForceScaled(force: { x: number; y: number }, origin?: { x: number; y: number }): void;
1363
+
870
1364
  /**
871
1365
  * Applies wind force to the sprite.
872
1366
  * @param strength the strength of the wind
@@ -875,22 +1369,41 @@ declare global {
875
1369
  * @param lift the force that is perpendicular to the relative velocity
876
1370
  */
877
1371
  applyWind(strength: number, angle: number, drag?: number, lift?: number): void;
1372
+
878
1373
  /**
879
1374
  * Applies a force to the sprite's center of mass attracting it to
880
1375
  * the given position.
881
- * @param x x coordinate or coordinate array or object with x and y properties
882
- * @param y
1376
+ * @param x x coordinate
1377
+ * @param y y coordinate
1378
+ * @param force
1379
+ */
1380
+ attractTo(x: number, y: number, force?: number): void;
1381
+
1382
+ /**
1383
+ * Applies a force to the sprite's center of mass attracting it to
1384
+ * the given position.
1385
+ * @param pos object with x and y properties
883
1386
  * @param force
884
1387
  */
885
- attractTo(x: number | any, y?: number, force?: number): void;
1388
+ attractTo(pos: { x: number; y: number }, force?: number): void;
1389
+
886
1390
  /**
887
- * Applies a force to the sprite's center of mass repelling it to
1391
+ * Applies a force to the sprite's center of mass repelling it from
888
1392
  * the given position.
889
- * @param x x coordinate or coordinate array or object with x and y properties
890
- * @param y
1393
+ * @param x x coordinate
1394
+ * @param y y coordinate
1395
+ * @param force
1396
+ */
1397
+ repelFrom(x: number, y: number, force?: number): void;
1398
+
1399
+ /**
1400
+ * Applies a force to the sprite's center of mass repelling it from
1401
+ * the given position.
1402
+ * @param pos object with x and y properties
891
1403
  * @param force
892
1404
  */
893
- repelFrom(x: number | any, y?: number, force?: number): void;
1405
+ repelFrom(pos: { x: number; y: number }, force?: number): void;
1406
+
894
1407
  /**
895
1408
  * Apply a torque on the sprite's physics body.
896
1409
  * Torque is the force that causes rotation.
@@ -900,71 +1413,192 @@ declare global {
900
1413
  * This function is the rotational equivalent of applyForce().
901
1414
  * It will not imperatively set the sprite's rotation.
902
1415
  *
903
- * @param torque
1416
+ * @param torque
1417
+ */
1418
+ applyTorque(torque: any): void;
1419
+
1420
+ /**
1421
+ * Attempts to move the sprite to a destination at a constant speed
1422
+ * and stops the sprite if it reaches the destination.
1423
+ *
1424
+ * The destination check is deferred until the sprite is estimated to be
1425
+ * at the target position, based on `world.physicsTime`.
1426
+ *
1427
+ * @param x destination x, or `null` to only move on the y-axis
1428
+ * @param y destination y, or `null` to only move on the x-axis
1429
+ * @param speed movement speed in pixels per frame, defaults to the sprite's current speed or 1
1430
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1431
+ * destination, or `false` if it didn't.
1432
+ */
1433
+ moveTo(x: number | null, y: number | null, speed?: number): PromiseLike<boolean>;
1434
+
1435
+ /**
1436
+ * Attempts to move the sprite to a destination at a constant speed
1437
+ * and stops the sprite if it reaches the destination.
1438
+ *
1439
+ * @param pos destination object with x and y properties
1440
+ * @param speed movement speed in pixels per frame, defaults to the sprite's current speed or 1
1441
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1442
+ * destination, or `false` if it didn't.
1443
+ */
1444
+ moveTo(pos: { x: number | null; y: number | null }, speed?: number): PromiseLike<boolean>;
1445
+
1446
+ /**
1447
+ * Moves the sprite towards a position at a percentage of the distance
1448
+ * between itself and the destination.
1449
+ *
1450
+ * @param x destination x, or `null` to only move on the y-axis
1451
+ * @param y destination y, or `null` to only move on the x-axis
1452
+ * @param tracking percent of the distance to move towards the destination as a 0-1 value, default is 0.1 (10% tracking)
1453
+ */
1454
+ moveTowards(x: number | null, y: number | null, tracking?: number): void;
1455
+
1456
+ /**
1457
+ * Moves the sprite towards a position at a percentage of the distance
1458
+ * between itself and the destination.
1459
+ *
1460
+ * @param pos destination object with x and y properties
1461
+ * @param tracking percent of the distance to move towards the destination as a 0-1 value, default is 0.1 (10% tracking)
1462
+ */
1463
+ moveTowards(pos: { x: number | null; y: number | null }, tracking?: number): void;
1464
+
1465
+ /**
1466
+ * Rotates the sprite to a target angle at a constant speed,
1467
+ * stopping if it arrives.
1468
+ *
1469
+ * The destination check is deferred until the sprite is estimated to be
1470
+ * at the target angle, based on `world.physicsTime`.
1471
+ *
1472
+ * @param angle target rotation angle
1473
+ * @param speed rotation speed in degrees (or radians) per frame, defaults to the sprite's current rotationSpeed or 1
1474
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1475
+ * target angle, or `false` if it didn't.
1476
+ */
1477
+ rotateTo(angle: number, speed?: number): PromiseLike<boolean>;
1478
+
1479
+ /**
1480
+ * Rotates the sprite to face a position at a constant speed,
1481
+ * stopping if it arrives.
1482
+ *
1483
+ * @param pos object with x and y properties
1484
+ * @param speed rotation speed in degrees (or radians) per frame, defaults to the sprite's current rotationSpeed or 1
1485
+ * @param facing rotation angle the sprite should be at when "facing" the position, default is 0
1486
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1487
+ * target angle, or `false` if it didn't.
1488
+ */
1489
+ rotateTo(pos: { x: number; y: number }, speed?: number, facing?: number): PromiseLike<boolean>;
1490
+
1491
+ /**
1492
+ * Rotates the sprite by the smallest angular distance to a target angle
1493
+ * at a constant speed, stopping when it arrives.
1494
+ *
1495
+ * @param angle target rotation angle
1496
+ * @param speed absolute rotation per frame, defaults to the sprite's current rotationSpeed or 1
1497
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1498
+ * target angle, or `false` if it didn't.
1499
+ */
1500
+ rotateMinTo(angle: number, speed?: number): PromiseLike<boolean>;
1501
+
1502
+ /**
1503
+ * Rotates the sprite by the smallest angular distance to face a position
1504
+ * at a constant speed, stopping when it arrives.
1505
+ *
1506
+ * @param pos object with x and y properties
1507
+ * @param speed absolute rotation per frame, defaults to the sprite's current rotationSpeed or 1
1508
+ * @param facing rotation angle the sprite should be at when "facing" the position, default is 0
1509
+ * @returns a lazy thenable that resolves `true` if the sprite reached the
1510
+ * target angle, or `false` if it didn't.
904
1511
  */
905
- applyTorque(torque: any): void;
1512
+ rotateMinTo(pos: { x: number; y: number }, speed?: number, facing?: number): PromiseLike<boolean>;
1513
+
906
1514
  /**
907
- * Moves a sprite towards a position at a percentage of the distance
908
- * between itself and the destination.
1515
+ * Rotates the sprite towards an angle.
909
1516
  *
910
- * @param x destination x or coordinate array or an object with x and y properties
911
- * @param y destination y
912
- * @param tracking percent of the distance to move towards the destination as a 0-1 value, default is 0.1 (10% tracking)
1517
+ * @param angle angle in degrees
1518
+ * @param tracking percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%)
913
1519
  */
914
- moveTowards(x: number | any, y?: number, tracking?: number): void;
1520
+ rotateTowards(angle: number, tracking?: number): void;
1521
+
915
1522
  /**
916
- * Moves the sprite away from a position, the opposite of moveTowards,
917
- * at a percentage of the distance between itself and the position.
918
- * @param x destination x or coordinate array or an object with x and y properties
919
- * @param y destination y
920
- * @param repel percent of the distance to the repel position as a 0-1 value, default is 0.1 (10% repel)
1523
+ * Rotates the sprite towards a position.
1524
+ *
1525
+ * @param pos object with x and y properties
1526
+ * @param tracking percent of the distance to rotate on each frame towards the target position, default is 0.1 (10%)
1527
+ * @param facing rotation angle the sprite should be at when "facing" the position, default is 0
921
1528
  */
922
- moveAway(x: number | any, y?: number, repel?: number): void;
1529
+ rotateTowards(pos: { x: number; y: number }, tracking?: number, facing?: number): void;
1530
+
923
1531
  /**
924
- * Rotates the sprite towards an angle or position
925
- * with x and y properties.
1532
+ * Finds the angle from this sprite to the given position.
926
1533
  *
927
- * @param angle angle in degrees or coordinate array or an object with x and y properties
928
- * @param tracking percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%)
929
- * @param facing (only specify if position is given) rotation angle the sprite should be at when "facing" the position, default is 0
1534
+ * Equivalent to `atan2(y - sprite.y, x - sprite.x) + facing`.
1535
+ * Returns the sprite's current rotation if the position is within 0.01 pixels.
1536
+ *
1537
+ * Can be used to set the direction of a sprite so it moves toward a position.
1538
+ *
1539
+ * @param x x coordinate
1540
+ * @param y y coordinate
1541
+ * @param facing offset angle added to the result, default is 0
1542
+ * @returns angle to the position
930
1543
  */
931
- rotateTowards(angle: number | any, tracking?: number): void;
1544
+ angleTo(x: number, y: number, facing?: number): number;
932
1545
  /**
933
1546
  * Finds the angle from this sprite to the given position.
934
1547
  *
935
- * Can be used to change the direction of a sprite so it moves
936
- * to a position or object, as shown in the example.
1548
+ * @param pos object with x and y properties
1549
+ * @param facing offset angle added to the result, default is 0
1550
+ * @returns angle to the position
1551
+ */
1552
+ angleTo(pos: { x: number; y: number }, facing?: number): number;
1553
+
1554
+ /**
1555
+ * Finds the minimum angular distance the sprite would need to rotate
1556
+ * to face a position, taking into account the sprite's current rotation.
937
1557
  *
938
- * Used internally by `moveTo` and `moveTowards`.
1558
+ * Useful for `rotateTowards`-style logic where you need the signed delta
1559
+ * rather than an absolute target angle.
939
1560
  *
940
- * @param x x coordinate or coordinate array or object with x and y properties
941
- * @param y
942
- * @returns angle
1561
+ * @param x x coordinate
1562
+ * @param y y coordinate
1563
+ * @param facing offset angle, default is 0
1564
+ * @returns the minimum angular distance to face the position
943
1565
  */
944
- angleTo(x: number | any, y?: number): number;
1566
+ angleDistTo(x: number, y: number, facing?: number): number;
1567
+
945
1568
  /**
946
- * Finds the rotation angle the sprite should be at when "facing"
947
- * a position.
1569
+ * Finds the minimum angular distance the sprite would need to rotate
1570
+ * to face a position, taking into account the sprite's current rotation.
948
1571
  *
949
- * @param x x coordinate or coordinate array or object with x and y properties
950
- * @param y
951
- * @param facing relative angle the sprite should be at when "facing" the position, default is 0
952
- * @returns the rotation angle the sprite should be at when "facing" the position
1572
+ * @param pos object with x and y properties
1573
+ * @param facing offset angle, default is 0
1574
+ * @returns the minimum angular distance to face the position
953
1575
  */
954
- rotationToFace(x: number | any, y?: number, facing?: number): number;
1576
+ angleDistTo(pos: { x: number; y: number }, facing?: number): number;
1577
+
955
1578
  /**
956
- * Finds the minimum angle distance that the sprite would have
957
- * to rotate to "face" a position at a specified facing rotation,
958
- * taking into account the current rotation of the sprite.
1579
+ * Moves and rotates a sprite's physics body towards a target transform
1580
+ * at a percentage of the distance on each frame.
959
1581
  *
960
- * Used internally by `rotateTowards`.
1582
+ * Uses Box2D's `b2Body_SetTargetTransform` for maximum efficiency
1583
+ * compared to using `moveTowards` and `rotateTowards` separately.
961
1584
  *
962
- * @param x x coordinate or coordinate array or object with x and y properties
963
- * @param y
964
- * @param facing relative angle the sprite should be at when "facing" the position, default is 0
965
- * @returns the minimum angle distance to face the position
1585
+ * @param x destination x
1586
+ * @param y destination y
1587
+ * @param rotation target rotation angle
1588
+ * @param tracking percent of the distance to move towards the target as a 0-1 value, default is 0.1 (10% tracking)
1589
+ */
1590
+ transformTowards(x: number, y: number, rotation?: number, tracking?: number): void;
1591
+
1592
+ /**
1593
+ * Moves and rotates a sprite's physics body towards a target transform
1594
+ * at a percentage of the distance on each frame.
1595
+ *
1596
+ * @param pos destination object with x and y properties
1597
+ * @param rotation target rotation angle
1598
+ * @param tracking percent of the distance to move towards the target as a 0-1 value, default is 0.1 (10% tracking)
966
1599
  */
967
- angleToFace(x: number | any, y?: number, facing?: number): number;
1600
+ transformTowards(pos: { x: number; y: number }, rotation?: number, tracking?: number): void;
1601
+
968
1602
  /**
969
1603
  * Deletes the Sprite from the sketch and all the groups it
970
1604
  * belongs to.
@@ -976,11 +1610,13 @@ declare global {
976
1610
  * sprite use `sprite.visible = false` instead.
977
1611
  */
978
1612
  delete(): void;
1613
+
979
1614
  /**
980
1615
  * Returns the sprite's unique identifier `sprite.idNum`.
981
1616
  * @returns the sprite's id
982
1617
  */
983
1618
  toString(): string;
1619
+
984
1620
  /**
985
1621
  * Returns true on the first frame that the sprite collides with the
986
1622
  * target sprite or group.
@@ -992,6 +1628,7 @@ declare global {
992
1628
  * @param callback
993
1629
  */
994
1630
  collides(target: Sprite | Group, callback?: Function): boolean;
1631
+
995
1632
  /**
996
1633
  * Returns a truthy value while the sprite is colliding with the
997
1634
  * target sprite or group. The value is the number of frames that
@@ -1002,6 +1639,7 @@ declare global {
1002
1639
  * @return {Number} frames
1003
1640
  */
1004
1641
  colliding(target: Sprite | Group, callback?: Function): number;
1642
+
1005
1643
  /**
1006
1644
  * Returns true on the first frame that the sprite no longer overlaps
1007
1645
  * with the target sprite or group.
@@ -1011,6 +1649,7 @@ declare global {
1011
1649
  * @return {Boolean}
1012
1650
  */
1013
1651
  collided(target: Sprite | Group, callback?: Function): boolean;
1652
+
1014
1653
  /**
1015
1654
  * Returns true on the first frame that the sprite overlaps with the
1016
1655
  * target sprite or group.
@@ -1022,6 +1661,7 @@ declare global {
1022
1661
  * @param callback
1023
1662
  */
1024
1663
  overlaps(target: Sprite | Group, callback?: Function): boolean;
1664
+
1025
1665
  /**
1026
1666
  * Returns a truthy value while the sprite is overlapping with the
1027
1667
  * target sprite or group. The value returned is the number of
@@ -1032,6 +1672,7 @@ declare global {
1032
1672
  * @return {Number} frames
1033
1673
  */
1034
1674
  overlapping(target: Sprite | Group, callback?: Function): number;
1675
+
1035
1676
  /**
1036
1677
  * Returns true on the first frame that the sprite no longer overlaps
1037
1678
  * with the target sprite or group.
@@ -1041,18 +1682,21 @@ declare global {
1041
1682
  * @return {Boolean}
1042
1683
  */
1043
1684
  overlapped(target: Sprite | Group, callback?: Function): boolean;
1685
+
1044
1686
  /**
1045
1687
  * Sets a pass through contact relationship between the sprite
1046
1688
  * and a target sprite or group.
1047
1689
  * @param target
1048
1690
  */
1049
1691
  pass(target: Sprite | Group): void;
1692
+
1050
1693
  /**
1051
1694
  * Sets a pass through contact relationship between the sprite
1052
1695
  * and a target sprite or group.
1053
1696
  * @param target
1054
1697
  */
1055
1698
  passes(target: Sprite | Group): void;
1699
+
1056
1700
  /**
1057
1701
  * Creates overlap sensors that are the same size as the sprite's
1058
1702
  * colliders. If you'd like to add more sensors to a sprite, use the
@@ -1062,14 +1706,23 @@ declare global {
1062
1706
  * function is called but the sprite has no overlap sensors.
1063
1707
  */
1064
1708
  addDefaultSensors(): void;
1709
+
1065
1710
  /**
1066
- * Returns the distance to another sprite, the mouse, a touch,
1067
- * or any other object with x and y properties. Uses p5's `dist`
1068
- * function.
1069
- * @param o coordinate array or object with x and y properties
1711
+ * Returns the distance to another sprite, the mouse, a touch pointer,
1712
+ * or any other object with x and y properties. Uses q5's `dist` function.
1713
+ * @param x
1714
+ * @param y
1715
+ * @returns distance
1716
+ */
1717
+ distanceTo(x: number, y: number): number;
1718
+
1719
+ /**
1720
+ * Returns the distance to another sprite, the mouse, a touch pointer,
1721
+ * or any other object with x and y properties. Uses q5's `dist` function.
1722
+ * @param pos object with x and y properties
1070
1723
  * @returns distance
1071
1724
  */
1072
- distanceTo(o: any): number;
1725
+ distanceTo(pos: { x: number; y: number }): number;
1073
1726
  }
1074
1727
 
1075
1728
  class Ani extends Array<Q5.Image> {
@@ -1080,11 +1733,13 @@ declare global {
1080
1733
  * @param args the frames of the animation
1081
1734
  */
1082
1735
  constructor(...args: Q5.Image[]);
1736
+
1083
1737
  /**
1084
1738
  * The name of the animation
1085
1739
  */
1086
1740
  name: string;
1087
1741
  targetFrame: number;
1742
+
1088
1743
  /**
1089
1744
  * The distance from the sprite or visual's position
1090
1745
  * that the animation is drawn at.
@@ -1092,21 +1747,25 @@ declare global {
1092
1747
  * @prop {Number} y vertical offset
1093
1748
  */
1094
1749
  offset: { x: number; y: number };
1750
+
1095
1751
  /**
1096
1752
  * True if the animation is currently playing.
1097
1753
  * @default true
1098
1754
  */
1099
1755
  playing: boolean;
1756
+
1100
1757
  /**
1101
1758
  * Animation visibility.
1102
1759
  * @default true
1103
1760
  */
1104
1761
  visible: boolean;
1762
+
1105
1763
  /**
1106
1764
  * If set to false the animation will stop after reaching the last frame
1107
1765
  * @default true
1108
1766
  */
1109
1767
  looping: boolean;
1768
+
1110
1769
  /**
1111
1770
  * Ends the loop on frame 0 instead of the last frame.
1112
1771
  * This is useful for animations that are symmetric.
@@ -1115,6 +1774,7 @@ declare global {
1115
1774
  * @default false
1116
1775
  */
1117
1776
  endOnFirstFrame: boolean;
1777
+
1118
1778
  /**
1119
1779
  * True if frame changed during the last draw cycle
1120
1780
  */
@@ -1123,11 +1783,13 @@ declare global {
1123
1783
  onChange: any;
1124
1784
  rotation: any;
1125
1785
  spriteSheet: any;
1786
+
1126
1787
  /**
1127
1788
  * The index of the current frame that the animation is on.
1128
1789
  */
1129
1790
  get frame(): number;
1130
1791
  set frame(val: number);
1792
+
1131
1793
  /**
1132
1794
  * Delay between frames in number of draw cycles.
1133
1795
  * If set to 4 the framerate of the animation would be the
@@ -1136,6 +1798,7 @@ declare global {
1136
1798
  */
1137
1799
  get frameDelay(): number;
1138
1800
  set frameDelay(val: number);
1801
+
1139
1802
  /**
1140
1803
  * The animation's scale.
1141
1804
  *
@@ -1145,30 +1808,36 @@ declare global {
1145
1808
  */
1146
1809
  get scale(): number | { x: number; y: number };
1147
1810
  set scale(val: number | { x: number; y: number });
1811
+
1148
1812
  /**
1149
1813
  * Make a copy of the animation, with its own playback state,
1150
1814
  * independent of the original animation.
1151
1815
  * @return {Ani}
1152
1816
  */
1153
1817
  clone(): Ani;
1818
+
1154
1819
  /**
1155
1820
  * Updates the animation's playback state. This is called automatically
1156
1821
  */
1157
1822
  update(): void;
1823
+
1158
1824
  /**
1159
1825
  * Plays the animation, starting from the specified frame.
1160
1826
  *
1161
1827
  * @returns [Promise] a promise that resolves when the animation completes
1162
1828
  */
1163
1829
  play(frame: any): Promise<any>;
1830
+
1164
1831
  /**
1165
1832
  * Pauses the animation.
1166
1833
  */
1167
1834
  pause(frame: any): void;
1835
+
1168
1836
  /**
1169
1837
  * Stops the animation. Alt for pause.
1170
1838
  */
1171
1839
  stop(frame: any): void;
1840
+
1172
1841
  /**
1173
1842
  * Plays the animation backwards.
1174
1843
  * Equivalent to ani.goToFrame(0)
@@ -1177,22 +1846,27 @@ declare global {
1177
1846
  * rewinding
1178
1847
  */
1179
1848
  rewind(): Promise<any>;
1849
+
1180
1850
  /**
1181
1851
  * Plays the animation forwards and loops it.
1182
1852
  */
1183
1853
  loop(): void;
1854
+
1184
1855
  /**
1185
1856
  * Prevents the animation from looping
1186
1857
  */
1187
1858
  noLoop(): void;
1859
+
1188
1860
  /**
1189
1861
  * Goes to the next frame and stops.
1190
1862
  */
1191
1863
  nextFrame(): void;
1864
+
1192
1865
  /**
1193
1866
  * Goes to the previous frame and stops.
1194
1867
  */
1195
1868
  previousFrame(): void;
1869
+
1196
1870
  /**
1197
1871
  * Plays the animation forward or backward toward a target frame.
1198
1872
  *
@@ -1200,33 +1874,40 @@ declare global {
1200
1874
  * @returns [Promise] a promise that resolves when the animation completes
1201
1875
  */
1202
1876
  goToFrame(toFrame: number): Promise<any>;
1877
+
1203
1878
  /**
1204
1879
  * The index of the last frame. Read only.
1205
1880
  */
1206
1881
  get lastFrame(): number;
1882
+
1207
1883
  /**
1208
1884
  * The current frame as Q5.Image. Read only.
1209
1885
  */
1210
1886
  get frameImage(): Q5.Image;
1887
+
1211
1888
  /**
1212
1889
  * Width of the animation's current frame.
1213
1890
  */
1214
1891
  get w(): number;
1892
+
1215
1893
  /**
1216
1894
  * Width of the animation's current frame.
1217
1895
  */
1218
1896
  get width(): number;
1219
1897
  get defaultWidth(): any;
1898
+
1220
1899
  /**
1221
1900
  * Height of the animation's current frame.
1222
1901
  */
1223
1902
  get h(): number;
1903
+
1224
1904
  /**
1225
1905
  * Height of the animation's current frame.
1226
1906
  */
1227
1907
  get height(): number;
1228
1908
  get defaultHeight(): any;
1229
1909
  }
1910
+
1230
1911
  /**
1231
1912
  * Stores animations.
1232
1913
  *
@@ -1241,6 +1922,7 @@ declare global {
1241
1922
  scale: number | { x: number; y: number };
1242
1923
  looping: boolean;
1243
1924
  playing: boolean;
1925
+
1244
1926
  /**
1245
1927
  * Cuts sprite sheet frames into separate images, instead of rendering
1246
1928
  * sections of the sprite sheet.
@@ -1249,15 +1931,18 @@ declare global {
1249
1931
  * but uses more memory and may cause longer load times.
1250
1932
  */
1251
1933
  cutFrames: boolean;
1934
+
1252
1935
  endOnFirstFrame: boolean;
1253
1936
  w: number;
1254
1937
  width: number;
1255
1938
  h: number;
1256
1939
  height: number;
1940
+
1257
1941
  /**
1258
1942
  * Frame size of the animations in the collection, in the format "WIDTHxHEIGHT", for example "32x32".
1259
1943
  */
1260
1944
  frameSize: string;
1945
+
1261
1946
  /**
1262
1947
  * The sprite sheet image used by the animations in the collection.
1263
1948
  */
@@ -1265,27 +1950,32 @@ declare global {
1265
1950
  }
1266
1951
 
1267
1952
  /**
1268
- * Visual objects store images and animations that can be displayed
1269
- * with respect to the camera.
1270
- */
1271
- class Visuals extends Array<Visual> {
1953
+ * A collection of and blueprint for Visual objects
1954
+ * that store an image or animation(s)
1955
+ * which can be displayed with respect to the camera.
1956
+ */
1957
+ class Visuals<T extends Visual = Visual> extends Array<T> {
1272
1958
  /**
1273
1959
  * Draws the visuals on the canvas.
1274
1960
  */
1275
1961
  draw(): void;
1962
+
1276
1963
  /**
1277
1964
  * Current image.
1278
1965
  */
1279
1966
  img: Q5.Image;
1967
+
1280
1968
  /**
1281
1969
  * Current animation.
1282
1970
  */
1283
1971
  ani: Ani;
1972
+
1284
1973
  /**
1285
1974
  * Stores animations.
1286
1975
  * Keys are the animation label, values are Ani objects
1287
1976
  */
1288
1977
  get anis(): Anis;
1978
+
1289
1979
  /**
1290
1980
  * Adds an animation to the Group or Visuals array.
1291
1981
  *
@@ -1294,6 +1984,26 @@ declare global {
1294
1984
  * @returns A promise that fulfills when the animation is loaded
1295
1985
  */
1296
1986
  addAni(spriteSheetURL: string, frameCount: number): Promise<void>;
1987
+
1988
+ /**
1989
+ * Add multiple animations to the Group or Visuals array.
1990
+ *
1991
+ * @param atlases an object with animation names as keys and
1992
+ * an animation or animation atlas as values
1993
+ * @returns A promise that fulfills when the animations are loaded
1994
+ */
1995
+ addAnis(atlases: {}): Promise<void>;
1996
+
1997
+ /**
1998
+ * Add multiple animations to the Group or Visuals array.
1999
+ *
2000
+ * @param spriteSheetURL the URL of the sprite sheet image
2001
+ * @param atlases an object with animation names as keys and
2002
+ * an animation or animation atlas as values
2003
+ * @returns A promise that fulfills when the animations are loaded
2004
+ */
2005
+ addAnis(spriteSheetURL: string, atlases: {}): Promise<void>;
2006
+
1297
2007
  /**
1298
2008
  * Add multiple animations to the Group or Visuals array.
1299
2009
  *
@@ -1304,6 +2014,7 @@ declare global {
1304
2014
  * @returns A promise that fulfills when the animations are loaded
1305
2015
  */
1306
2016
  addAnis(spriteSheetURL: string, frameSize: string, atlases: {}): Promise<void>;
2017
+
1307
2018
  /**
1308
2019
  * Detects when visuals go outside the given culling boundary,
1309
2020
  * relative to the camera.
@@ -1316,10 +2027,12 @@ declare global {
1316
2027
  * @return {Number} the number of visuals culled
1317
2028
  */
1318
2029
  cull(top?: number, bottom?: number, left?: number, right?: number, cb?: Function): number;
2030
+
1319
2031
  /**
1320
2032
  * The tile character that represents the Visuals or Group in a tile map.
1321
2033
  */
1322
2034
  tile: string;
2035
+
1323
2036
  /**
1324
2037
  * Adds sprites to the group based on a tile map.
1325
2038
  *
@@ -1332,19 +2045,28 @@ declare global {
1332
2045
  addTiles(tiles: string | string[], x?: number, y?: number, colWidth?: number, rowHeight?: number): void;
1333
2046
  }
1334
2047
 
1335
- class Group extends Visuals {
2048
+ /**
2049
+ * A Group is a collection of and blueprint for
2050
+ * sprites with similar traits and behaviors.
2051
+ */
2052
+ class Group extends Visuals<Sprite> {
1336
2053
  /**
1337
- * An array of sprites with similar traits and behaviors.
2054
+ * A Group is a collection of and blueprint for
2055
+ * sprites with similar traits and behaviors.
1338
2056
  *
1339
- * Group extends Array, so you can use them in for of loops. They
1340
- * inherit all the functions and properties of standard arrays
2057
+ * Group extends Visuals which extends Array,
2058
+ * so you can use them in for loops. They've got
2059
+ * all the functions and properties of standard arrays
1341
2060
  * such as `group.length` and functions like `group.includes()`.
1342
2061
  *
1343
2062
  * Changing a group setting changes it for all the sprites in the
1344
- * group, similar to class inheritance. Groups can have subgroups,
1345
- * creating a hierarchy of inheritance.
2063
+ * group ("dynamic inheritance").
1346
2064
  *
1347
- * @param sprites the sprites to add to the group
2065
+ * All groups inherit from the base group `allSprites`.
2066
+ *
2067
+ * Groups can have subgroups, creating a hierarchy of inheritance.
2068
+ *
2069
+ * @param [sprites] the sprites to add to the group
1348
2070
  */
1349
2071
  constructor(...sprites: Sprite[]);
1350
2072
 
@@ -1352,18 +2074,22 @@ declare global {
1352
2074
  * Horizontal position of group sprites.
1353
2075
  */
1354
2076
  x: number;
2077
+
1355
2078
  /**
1356
2079
  * Vertical position of group sprites.
1357
2080
  */
1358
2081
  y: number;
2082
+
1359
2083
  /**
1360
2084
  * Velocity of group sprites.
1361
2085
  */
1362
2086
  vel: number;
2087
+
1363
2088
  /**
1364
2089
  * Velocity of group sprites.
1365
2090
  */
1366
2091
  velocity: number;
2092
+
1367
2093
  /**
1368
2094
  * The angle of the group sprites' rotation, not the direction it's moving.
1369
2095
  *
@@ -1371,6 +2097,7 @@ declare global {
1371
2097
  * a range of -180 to 180.
1372
2098
  */
1373
2099
  rotation: number;
2100
+
1374
2101
  /**
1375
2102
  * The speed of the group sprites' rotation in angles per frame.
1376
2103
  */
@@ -1380,6 +2107,7 @@ declare global {
1380
2107
  * If true, group sprites are drawn by q5play after each physics update.
1381
2108
  */
1382
2109
  autoDraw: boolean;
2110
+
1383
2111
  /**
1384
2112
  * Controls the ability for group sprites to "sleep".
1385
2113
  *
@@ -1388,10 +2116,12 @@ declare global {
1388
2116
  * with anything that it wasn't already colliding with.
1389
2117
  */
1390
2118
  allowSleeping: boolean;
2119
+
1391
2120
  /**
1392
2121
  * If true, group sprites are updated by q5play before each physics update.
1393
2122
  */
1394
2123
  autoUpdate: number;
2124
+
1395
2125
  /**
1396
2126
  * A bearing indicates the direction that needs to be followed to
1397
2127
  * reach a destination.
@@ -1401,38 +2131,46 @@ declare global {
1401
2131
  * using the `applyForce` function.
1402
2132
  */
1403
2133
  bearing: number;
2134
+
1404
2135
  /**
1405
2136
  * The bounciness of the group sprites' physics body.
1406
2137
  */
1407
2138
  bounciness: number;
2139
+
1408
2140
  /**
1409
2141
  * The group sprites' current fill color.
1410
2142
  *
1411
2143
  * By default sprites get a random color.
1412
2144
  */
1413
2145
  color: Q5.Color;
2146
+
1414
2147
  /**
1415
2148
  * The diameter of a circular sprite.
1416
2149
  */
1417
2150
  d: number;
2151
+
1418
2152
  /**
1419
2153
  * The diameter of a circular sprite.
1420
2154
  */
1421
2155
  diameter: number;
2156
+
1422
2157
  /**
1423
2158
  * If true, outlines of the group sprites' colliders and sensors will be drawn.
1424
2159
  *
1425
2160
  * Use the keyboard shortcut Command+B to toggle `allSprites.debug`.
1426
2161
  */
1427
2162
  debug: boolean;
2163
+
1428
2164
  /**
1429
2165
  * The density of the group sprites' physics body.
1430
2166
  */
1431
2167
  density: number;
2168
+
1432
2169
  /**
1433
2170
  * The angle of the group sprites' movement.
1434
2171
  */
1435
2172
  direction: number;
2173
+
1436
2174
  /**
1437
2175
  * The amount of resistance group sprites has to being moved.
1438
2176
  */
@@ -1443,14 +2181,17 @@ declare global {
1443
2181
  * when rubbing against other colliders.
1444
2182
  */
1445
2183
  friction: number;
2184
+
1446
2185
  /**
1447
2186
  * Whether the group sprites can be grabbed by a pointer.
1448
2187
  */
1449
2188
  grabbable: boolean;
2189
+
1450
2190
  /**
1451
2191
  * A ratio that defines how much the group sprites are affected by gravity.
1452
2192
  */
1453
2193
  gravityScale: number;
2194
+
1454
2195
  /**
1455
2196
  * The group sprites' heading. This is a string that can be set to
1456
2197
  * "up", "down", "left", "right", "upRight", "upLeft", "downRight"
@@ -1459,25 +2200,30 @@ declare global {
1459
2200
  * underscores, dashes, and cardinal direction word order.
1460
2201
  */
1461
2202
  heading: string;
2203
+
1462
2204
  /**
1463
2205
  * The height of the group sprites.
1464
2206
  */
1465
2207
  h: number;
2208
+
1466
2209
  /**
1467
2210
  * The height of the group sprites.
1468
2211
  */
1469
2212
  height: number;
2213
+
1470
2214
  /**
1471
2215
  * Set this to true if the group sprites goes really fast to prevent
1472
2216
  * inaccurate physics simulation.
1473
2217
  */
1474
2218
  isSuperFast: boolean;
2219
+
1475
2220
  /**
1476
2221
  * Sprites with the highest layer value get drawn first.
1477
2222
  *
1478
2223
  * By default sprites are drawn in the order they were created in.
1479
2224
  */
1480
2225
  layer: number;
2226
+
1481
2227
  /**
1482
2228
  * When the physics simulation is progressed in `world.physicsUpdate`,
1483
2229
  * each sprite's life is decreased by `world.timeScale`.
@@ -1486,10 +2232,12 @@ declare global {
1486
2232
  * be removed.
1487
2233
  */
1488
2234
  life: number;
2235
+
1489
2236
  /**
1490
2237
  * The mass of the group sprites' physics body.
1491
2238
  */
1492
2239
  mass: number;
2240
+
1493
2241
  /**
1494
2242
  * The physics type of the group sprites, which determines how it interacts with
1495
2243
  * other sprites in the physics simulation.
@@ -1497,6 +2245,7 @@ declare global {
1497
2245
  * It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
1498
2246
  */
1499
2247
  physics: string;
2248
+
1500
2249
  /**
1501
2250
  * The physics type of the group sprites, which determines how it interacts with
1502
2251
  * other sprites in the physics simulation.
@@ -1504,10 +2253,12 @@ declare global {
1504
2253
  * It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
1505
2254
  */
1506
2255
  physicsType: string;
2256
+
1507
2257
  /**
1508
2258
  * If true, the group sprites' physics body is included in the physics simulation.
1509
2259
  */
1510
2260
  physicsEnabled: boolean;
2261
+
1511
2262
  /**
1512
2263
  * If true, q5play will draw sprites at integer pixel precision.
1513
2264
  *
@@ -1516,19 +2267,23 @@ declare global {
1516
2267
  * By default q5play draws sprites with subpixel rendering.
1517
2268
  */
1518
2269
  pixelPerfect: boolean;
2270
+
1519
2271
  /**
1520
2272
  * Simulates friction that slows down group sprites rolling on another sprite,
1521
2273
  * like a soccer ball rolling to a stop on high grass.
1522
2274
  */
1523
2275
  rollingResistance: number;
2276
+
1524
2277
  /**
1525
2278
  * The amount the group sprites resists rotating.
1526
2279
  */
1527
2280
  rotationDrag: number;
2281
+
1528
2282
  /**
1529
2283
  * If true, the group sprites can not rotate.
1530
2284
  */
1531
2285
  rotationLock: boolean;
2286
+
1532
2287
  /**
1533
2288
  * Horizontal and vertical scale of the group sprites.
1534
2289
  *
@@ -1538,7 +2293,7 @@ declare global {
1538
2293
  * number. This enables users to do things like `sprite.scale *= 2`
1539
2294
  * to double the group sprites' scale.
1540
2295
  */
1541
- scale: number | Q5.Vector;
2296
+ scale: number | [] | { x: number; y: number };
1542
2297
 
1543
2298
  /**
1544
2299
  * Wake group sprites up or put it to sleep.
@@ -1548,14 +2303,17 @@ declare global {
1548
2303
  * with anything that it wasn't already colliding with.
1549
2304
  */
1550
2305
  sleeping: boolean;
2306
+
1551
2307
  /**
1552
2308
  * The group sprites' stroke color.
1553
2309
  */
1554
2310
  stroke: Q5.Color;
2311
+
1555
2312
  /**
1556
2313
  * The group sprites' stroke weight, the thickness of its outline.
1557
2314
  */
1558
2315
  strokeWeight: number;
2316
+
1559
2317
  /**
1560
2318
  * The group sprites' speed.
1561
2319
  *
@@ -1563,33 +2321,40 @@ declare global {
1563
2321
  * 180 degrees opposite of its current direction angle.
1564
2322
  */
1565
2323
  speed: number;
2324
+
1566
2325
  /**
1567
2326
  * The group sprites' speed along the surface of its collider(s),
1568
2327
  * like a conveyor belt.
1569
2328
  */
1570
2329
  surfaceSpeed: number;
2330
+
1571
2331
  /**
1572
2332
  * Text displayed at the center of the group sprites.
1573
2333
  */
1574
2334
  text: number;
2335
+
1575
2336
  /**
1576
2337
  * The group sprites' text fill color. Black by default.
1577
2338
  */
1578
2339
  textFill: Q5.Color;
2340
+
1579
2341
  /**
1580
2342
  * The group sprites' text stroke color.
1581
2343
  * No stroke by default, does not inherit from the sketch's stroke color.
1582
2344
  */
1583
2345
  textStroke: Q5.Color;
2346
+
1584
2347
  /**
1585
2348
  * The group sprites' text stroke weight, the thickness of its outline.
1586
2349
  * No stroke by default, does not inherit from the sketch's stroke weight.
1587
2350
  */
1588
2351
  textStrokeWeight: number;
2352
+
1589
2353
  /**
1590
2354
  * The group sprites' text size, the sketch's current textSize by default.
1591
2355
  */
1592
2356
  textSize: number;
2357
+
1593
2358
  /**
1594
2359
  * If true the group sprites are shown, if set to false the group sprites are hidden.
1595
2360
  *
@@ -1597,10 +2362,12 @@ declare global {
1597
2362
  * set to true again if it goes back on screen.
1598
2363
  */
1599
2364
  visible: boolean;
2365
+
1600
2366
  /**
1601
2367
  * The width of the group sprites.
1602
2368
  */
1603
2369
  w: number;
2370
+
1604
2371
  /**
1605
2372
  * The width of the group sprites.
1606
2373
  */
@@ -1611,6 +2378,7 @@ declare global {
1611
2378
  * It's useful for debugging.
1612
2379
  */
1613
2380
  idNum: number;
2381
+
1614
2382
  /**
1615
2383
  * Groups can have subgroups, which inherit the properties
1616
2384
  * of their parent groups.
@@ -1619,18 +2387,22 @@ declare global {
1619
2387
  subgroups: {
1620
2388
  [x: string]: any;
1621
2389
  }[];
2390
+
1622
2391
  /**
1623
2392
  * The direct parent group that this group inherits properties from.
1624
2393
  */
1625
2394
  parent: any;
2395
+
1626
2396
  /**
1627
2397
  * Creates a new sprite with the traits of the group and adds it to the group.
1628
2398
  */
1629
2399
  Sprite: typeof Sprite;
2400
+
1630
2401
  /**
1631
2402
  * Creates a new subgroup that inherits the traits of the group.
1632
2403
  */
1633
2404
  Group: typeof Group;
2405
+
1634
2406
  /**
1635
2407
  * A property of the `allSprites` group only,
1636
2408
  * that controls whether sprites are automatically deleted
@@ -1640,28 +2412,33 @@ declare global {
1640
2412
  * remain false for the rest of the sketch, unless changed.
1641
2413
  */
1642
2414
  autoCull: boolean;
2415
+
1643
2416
  /**
1644
2417
  * New group sprites will not have physics bodies (can't have colliders).
1645
2418
  */
1646
2419
  visualOnly: boolean;
2420
+
1647
2421
  /**
1648
2422
  * Alias for `group.push`.
1649
2423
  *
1650
2424
  * Adds a sprite to the end of the group.
1651
2425
  */
1652
2426
  add: (...sprites: Sprite[]) => number;
2427
+
1653
2428
  /**
1654
2429
  * Alias for `group.includes`.
1655
2430
  *
1656
2431
  * Check if a sprite is in the group.
1657
2432
  */
1658
2433
  contains: (searchElement: Sprite, fromIndex?: number) => boolean;
2434
+
1659
2435
  /**
1660
2436
  * Depending on the value that the amount property is set to, the group will
1661
2437
  * either add or delete sprites.
1662
2438
  */
1663
2439
  get amount(): number;
1664
2440
  set amount(val: number);
2441
+
1665
2442
  /**
1666
2443
  * Returns true on the first frame that the group collides with the
1667
2444
  * target group.
@@ -1673,6 +2450,7 @@ declare global {
1673
2450
  * @param callback
1674
2451
  */
1675
2452
  collides(target: Group, callback?: Function): boolean;
2453
+
1676
2454
  /**
1677
2455
  * Returns the amount of frames that the group has been colliding
1678
2456
  * with the target group for, which is a truthy value. Returns 0 if
@@ -1683,6 +2461,7 @@ declare global {
1683
2461
  * @return {Number} frames
1684
2462
  */
1685
2463
  colliding(target: Group, callback?: Function): number;
2464
+
1686
2465
  /**
1687
2466
  * Returns true on the first frame that the group no longer overlaps
1688
2467
  * with the target group.
@@ -1692,6 +2471,7 @@ declare global {
1692
2471
  * @return {Boolean}
1693
2472
  */
1694
2473
  collided(target: Group, callback?: Function): boolean;
2474
+
1695
2475
  /**
1696
2476
  * Returns true on the first frame that the group overlaps with the
1697
2477
  * target group.
@@ -1703,6 +2483,7 @@ declare global {
1703
2483
  * @param callback
1704
2484
  */
1705
2485
  overlaps(target: Group, callback?: Function): boolean;
2486
+
1706
2487
  /**
1707
2488
  * Returns the amount of frames that the group has been overlapping
1708
2489
  * with the target group for, which is a truthy value. Returns 0 if
@@ -1713,6 +2494,7 @@ declare global {
1713
2494
  * @return {Number} frames
1714
2495
  */
1715
2496
  overlapping(target: Group, callback?: Function): number;
2497
+
1716
2498
  /**
1717
2499
  * Returns true on the first frame that the group no longer overlaps
1718
2500
  * with the target group.
@@ -1722,24 +2504,136 @@ declare global {
1722
2504
  * @return {Boolean}
1723
2505
  */
1724
2506
  overlapped(target: Group, callback?: Function): boolean;
2507
+
1725
2508
  /**
1726
2509
  * Sets a pass through contact relationship between the group and the target group.
1727
2510
  * @param target
1728
2511
  */
1729
2512
  pass(target: Group): void;
2513
+
1730
2514
  /**
1731
2515
  * Sets a pass through contact relationship between the group and the target group.
1732
2516
  * @param target
1733
2517
  */
1734
2518
  passes(target: Group): void;
1735
- applyForce(amount: number, origin?: [] | { x: number; y: number } | Q5.Vector): void;
1736
- applyForceScaled(amount: number, origin?: [] | { x: number; y: number } | Q5.Vector): void;
2519
+
2520
+ /**
2521
+ * Applies a force magnitude to the group at its bearing.
2522
+ */
2523
+ applyForce(amount: number, origin?: { x: number; y: number }): void;
2524
+
2525
+ /**
2526
+ * Applies a force vector to the group.
2527
+ */
2528
+ applyForce(force: { x: number; y: number }, origin?: { x: number; y: number }): void;
2529
+
2530
+ /**
2531
+ * Applies a force scaled to member masses using a magnitude.
2532
+ */
2533
+ applyForceScaled(amount: number, origin?: { x: number; y: number }): void;
2534
+
2535
+ /**
2536
+ * Applies a force scaled to member masses using a vector.
2537
+ */
2538
+ applyForceScaled(force: { x: number; y: number }, origin?: { x: number; y: number }): void;
1737
2539
  applyWind(speed: number, angle: number, drag?: number, lift?: number): void;
1738
- attractTo(x: number | any, y?: number, force?: number): void;
2540
+
2541
+ /**
2542
+ * Applies a force to the group's center of mass attracting it to
2543
+ * the given position.
2544
+ */
2545
+ attractTo(x: number, y: number, force?: number): void;
2546
+
2547
+ /**
2548
+ * Applies a force to the group's center of mass attracting it to
2549
+ * the given position.
2550
+ */
2551
+ attractTo(pos: { x: number; y: number }, force?: number): void;
1739
2552
  applyTorque(torque: any): void;
1740
- moveTowards(x: number | any, y?: number, tracking?: number): void;
1741
- moveAway(x: number | any, y?: number, repel?: number): void;
1742
- repelFrom(x: number | any, y?: number, force?: number): void;
2553
+
2554
+ /**
2555
+ * Moves each sprite in the group to a destination at a constant speed,
2556
+ * maintaining their relative offsets from the group's centroid.
2557
+ */
2558
+ moveTo(x: number | null, y: number | null, speed?: number): PromiseLike<boolean>;
2559
+
2560
+ /**
2561
+ * Moves each sprite in the group to a destination at a constant speed,
2562
+ * maintaining their relative offsets from the group's centroid.
2563
+ */
2564
+ moveTo(pos: { x: number | null; y: number | null }, speed?: number): PromiseLike<boolean>;
2565
+
2566
+ /**
2567
+ * Moves the group towards a position.
2568
+ */
2569
+ moveTowards(x: number | null, y: number | null, tracking?: number): void;
2570
+
2571
+ /**
2572
+ * Moves the group towards a position.
2573
+ */
2574
+ moveTowards(pos: { x: number | null; y: number | null }, tracking?: number): void;
2575
+
2576
+ /**
2577
+ * Rotates each sprite in the group to a target angle. The sign of `speed`
2578
+ * determines direction: positive = CW, negative = CCW.
2579
+ */
2580
+ rotateTo(angle: number, speed?: number): PromiseLike<boolean>;
2581
+
2582
+ /**
2583
+ * Rotates each sprite in the group to face a position. The sign of `speed`
2584
+ * determines direction: positive = CW, negative = CCW.
2585
+ */
2586
+ rotateTo(pos: { x: number; y: number }, speed?: number, facing?: number): PromiseLike<boolean>;
2587
+
2588
+ /**
2589
+ * Rotates each sprite in the group by the given angle amount at the given speed.
2590
+ */
2591
+ rotate(angle: number, speed?: number): PromiseLike<boolean>;
2592
+
2593
+ /**
2594
+ * Rotates each sprite in the group by the smallest angular distance to
2595
+ * a target angle, stopping when they arrive.
2596
+ */
2597
+ rotateMinTo(angle: number, speed?: number): PromiseLike<boolean>;
2598
+
2599
+ /**
2600
+ * Rotates each sprite in the group by the smallest angular distance to
2601
+ * face a position, stopping when they arrive.
2602
+ */
2603
+ rotateMinTo(pos: { x: number; y: number }, speed?: number, facing?: number): PromiseLike<boolean>;
2604
+
2605
+ /**
2606
+ * Rotates each sprite in the group towards an angle.
2607
+ */
2608
+ rotateTowards(angle: number, tracking?: number): void;
2609
+
2610
+ /**
2611
+ * Rotates each sprite in the group towards a position.
2612
+ */
2613
+ rotateTowards(pos: { x: number; y: number }, tracking?: number, facing?: number): void;
2614
+
2615
+ /**
2616
+ * Moves and rotates each sprite in the group towards a target transform,
2617
+ * maintaining their relative offsets from the group's centroid.
2618
+ */
2619
+ transformTowards(x: number, y: number, rotation?: number, tracking?: number): void;
2620
+
2621
+ /**
2622
+ * Moves and rotates each sprite in the group towards a target transform,
2623
+ * maintaining their relative offsets from the group's centroid.
2624
+ */
2625
+ transformTowards(pos: { x: number; y: number }, rotation?: number, tracking?: number): void;
2626
+
2627
+ /**
2628
+ * Applies a repelling force from a position.
2629
+ */
2630
+ repelFrom(x: number, y: number, force?: number): void;
2631
+
2632
+ /**
2633
+ * Applies a repelling force from a position.
2634
+ */
2635
+ repelFrom(pos: { x: number; y: number }, force?: number): void;
2636
+
1743
2637
  /**
1744
2638
  * Detects when sprites go outside the given culling boundary
1745
2639
  * relative to the camera.
@@ -1757,6 +2651,7 @@ declare global {
1757
2651
  * @return {Number} the number of sprites culled
1758
2652
  */
1759
2653
  cull(top?: number, bottom?: number, left?: number, right?: number, cb?: Function): number;
2654
+
1760
2655
  /**
1761
2656
  * If removalCount is greater than 0, that amount of
1762
2657
  * sprites starting from the start index will be removed
@@ -1772,6 +2667,7 @@ declare global {
1772
2667
  * @return {Sprite[]} the removed sprites
1773
2668
  */
1774
2669
  splice(start: number, removalCount: number, ...sprites: Sprite[]): Sprite[];
2670
+
1775
2671
  /**
1776
2672
  * Removes a sprite from this group and its sub groups (if any),
1777
2673
  * but does not delete it from the world.
@@ -1780,6 +2676,13 @@ declare global {
1780
2676
  * @return {Sprite} the deleted sprite or undefined if the specified sprite was not found
1781
2677
  */
1782
2678
  remove(item: Sprite | number): Sprite;
2679
+
2680
+ /**
2681
+ * Removes all sprites from this group without deleting them.
2682
+ * @returns the removed sprites
2683
+ */
2684
+ removeAll(): Sprite[];
2685
+
1783
2686
  /**
1784
2687
  * Deletes the group and all its sprites
1785
2688
  * from the world and every other group they belong to.
@@ -1787,22 +2690,28 @@ declare global {
1787
2690
  * Don't attempt to use a group after deleting it.
1788
2691
  */
1789
2692
  delete(): void;
2693
+
1790
2694
  /**
1791
2695
  * Deletes all the sprites in the group.
1792
2696
  *
1793
2697
  * Does not delete the group itself.
1794
2698
  */
1795
2699
  deleteAll(): void;
2700
+
1796
2701
  /**
1797
2702
  * Updates all the sprites in the group.
1798
2703
  */
1799
2704
  update(): void;
2705
+
1800
2706
  /**
1801
2707
  * Draws all the sprites in the group.
1802
2708
  */
1803
2709
  draw(): void;
1804
2710
  }
1805
2711
 
2712
+ /**
2713
+ * The World is the Box2D physics simulation.
2714
+ */
1806
2715
  class World {
1807
2716
  /**
1808
2717
  * Gravity force vector that affects all dynamic physics colliders.
@@ -1812,6 +2721,7 @@ declare global {
1812
2721
  */
1813
2722
  get gravity(): any;
1814
2723
  set gravity(val: any);
2724
+
1815
2725
  /**
1816
2726
  * The lowest velocity an object can have before it is considered
1817
2727
  * to be at rest.
@@ -1824,10 +2734,12 @@ declare global {
1824
2734
  */
1825
2735
  get bounceThreshold(): number;
1826
2736
  set bounceThreshold(val: number);
2737
+
1827
2738
  /**
1828
2739
  * The time elapsed in the physics simulation in seconds.
1829
2740
  */
1830
2741
  physicsTime: number;
2742
+
1831
2743
  /**
1832
2744
  * Represents the size of a meter in pixels.
1833
2745
  *
@@ -1840,15 +2752,18 @@ declare global {
1840
2752
  * @default 60
1841
2753
  */
1842
2754
  meterSize: number;
2755
+
1843
2756
  /**
1844
2757
  * @default true
1845
2758
  */
1846
2759
  autoStep: boolean;
2760
+
1847
2761
  /**
1848
2762
  * Performs a physics simulation step that advances all sprites
1849
2763
  * forward in time by 1 / updateRate * timeScale if no timeStep is given.
1850
2764
  */
1851
2765
  physicsUpdate(timeStep?: number): void;
2766
+
1852
2767
  /**
1853
2768
  * A time scale of 1.0 represents real time.
1854
2769
  * Accepts decimal values between 0 and 2.
@@ -1856,6 +2771,7 @@ declare global {
1856
2771
  */
1857
2772
  get timeScale(): number;
1858
2773
  set timeScale(val: number);
2774
+
1859
2775
  /**
1860
2776
  * The fixed update rate of the physics simulation in hertz.
1861
2777
  *
@@ -1868,16 +2784,18 @@ declare global {
1868
2784
  */
1869
2785
  get updateRate(): number;
1870
2786
  set updateRate(val: number);
2787
+
1871
2788
  /**
1872
2789
  * The real time in seconds since the world was created, including
1873
2790
  * time spent paused.
1874
2791
  */
1875
2792
  get realTime(): number;
2793
+
1876
2794
  /**
1877
2795
  * Returns the sprites at a position, ordered by layer.
1878
2796
  *
1879
2797
  * Sprites must have a physics body to be detected.
1880
- * @param x x coordinate or coordinate array or object with x and y properties
2798
+ * @param x x coordinate or object with x and y properties
1881
2799
  * @param y
1882
2800
  * @param radius the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)
1883
2801
  * @param group limit results to a specific group,
@@ -1886,25 +2804,45 @@ declare global {
1886
2804
  * sprites drawn when the camera was active, true by default
1887
2805
  * @returns an array of sprites
1888
2806
  */
1889
- getSpritesAt(
1890
- x: number | any,
1891
- y?: number,
1892
- radius?: number,
1893
- group?: Group,
1894
- cameraActiveWhenDrawn?: boolean
1895
- ): Sprite[];
2807
+ getSpritesAt(x: number, y: number, radius?: number, group?: Group, cameraActiveWhenDrawn?: boolean): Sprite[];
2808
+
2809
+ /**
2810
+ * Returns the sprites at a position, ordered by layer.
2811
+ *
2812
+ * Sprites must have a physics body to be detected.
2813
+ * @param pos object with x and y properties
2814
+ * @param radius the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)
2815
+ * @param group limit results to a specific group, allSprites by default
2816
+ * @param cameraActiveWhenDrawn limit results to sprites drawn when the camera was active, true by default
2817
+ * @returns an array of sprites
2818
+ */
2819
+ getSpritesAt(pos: { x: number; y: number }, radius?: number, group?: Group, cameraActiveWhenDrawn?: boolean): Sprite[];
2820
+
1896
2821
  /**
1897
2822
  * Returns the sprite at the specified position
1898
2823
  * on the top most layer, drawn when the camera was on.
1899
2824
  *
1900
2825
  * The sprite must have a physics body to be detected.
1901
- * @param x x coordinate or coordinate array or object with x and y properties
2826
+ * @param x x coordinate or object with x and y properties
1902
2827
  * @param y
1903
2828
  * @param radius the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)
1904
2829
  * @param group the group to search
1905
2830
  * @returns a sprite
1906
2831
  */
1907
- getSpriteAt(x: number | any, y?: number, radius?: number, group?: Group): Sprite;
2832
+ getSpriteAt(x: number, y: number, radius?: number, group?: Group): Sprite;
2833
+
2834
+ /**
2835
+ * Returns the sprite at the specified position
2836
+ * on the top most layer, drawn when the camera was on.
2837
+ *
2838
+ * The sprite must have a physics body to be detected.
2839
+ * @param pos object with x and y properties
2840
+ * @param radius the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)
2841
+ * @param group the group to search
2842
+ * @returns a sprite
2843
+ */
2844
+ getSpriteAt(pos: { x: number; y: number }, radius?: number, group?: Group): Sprite;
2845
+
1908
2846
  /**
1909
2847
  * "Sleeping" sprites get temporarily ignored during physics
1910
2848
  * simulation. A sprite starts "sleeping" when it stops moving and
@@ -1916,39 +2854,131 @@ declare global {
1916
2854
  */
1917
2855
  get allowSleeping(): boolean;
1918
2856
  set allowSleeping(val: boolean);
2857
+
1919
2858
  /**
1920
2859
  * Finds the first sprite (with a physics body) that
1921
2860
  * intersects a ray (line).
1922
2861
  *
1923
- * @param startPos starting position of the ray cast
1924
- * @param direction direction of the ray
1925
- * @param maxDistance max distance the ray should check
2862
+ * @param startPos starting position of the ray cast, object with x and y properties or array [x, y]
2863
+ * @param direction direction angle of the ray
2864
+ * @param maxDistance max distance the ray should check, default 10000
1926
2865
  * @returns The first sprite the ray hits or undefined
1927
2866
  */
1928
- rayCast(startPos: any, direction: number, maxDistance: number): Sprite;
2867
+ rayCast(startPos: { x: number; y: number } | number[], direction: number, maxDistance?: number): Sprite;
2868
+
1929
2869
  /**
1930
- * Finds sprites (with physics bodies) that intersect
1931
- * a line (ray).
2870
+ * Finds the first sprite (with a physics body) that
2871
+ * intersects a ray from startPos to endPos.
1932
2872
  *
1933
2873
  * @param startPos starting position of the ray cast
1934
- * @param direction direction of the ray
1935
- * @param maxDistance max distance the ray should check
1936
- * @param limiter callback that's run each time the ray intersects a sprite, receives an intersected sprite as an input parameter, return true to stop the ray
2874
+ * @param endPos end position of the ray cast
2875
+ * @returns The first sprite the ray hits or undefined
2876
+ */
2877
+ rayCast(startPos: { x: number; y: number } | number[], endPos: { x: number; y: number } | number[]): Sprite;
2878
+
2879
+ /**
2880
+ * Finds all sprites (with physics bodies) that intersect
2881
+ * a ray (line), sorted by distance.
2882
+ *
2883
+ * @param startPos starting position of the ray cast, object with x and y properties or array [x, y]
2884
+ * @param direction direction angle of the ray
2885
+ * @param maxDistance max distance the ray should check, default 10000
2886
+ * @param limiter callback run each time the ray hits a sprite; return true to stop the ray
1937
2887
  * @returns An array of sprites that the ray cast hit, sorted by distance. The sprite closest to the starting point will be at index 0. If a limiter is provided, this array includes the sprite that caused the ray to stop.
1938
2888
  */
1939
- rayCastAll(startPos: any, direction: number, maxDistance: number, limiter?: Function): Sprite[];
2889
+ rayCastAll(startPos: { x: number; y: number } | number[], direction: number, maxDistance?: number, limiter?: Function): Sprite[];
2890
+
2891
+ /**
2892
+ * Finds all sprites (with physics bodies) that intersect
2893
+ * a ray from startPos to endPos, sorted by distance.
2894
+ *
2895
+ * @param startPos starting position of the ray cast
2896
+ * @param endPos end position of the ray cast
2897
+ * @param limiter callback run each time the ray hits a sprite; return true to stop the ray
2898
+ * @returns An array of sprites that the ray cast hit, sorted by distance.
2899
+ */
2900
+ rayCastAll(startPos: { x: number; y: number } | number[], endPos: { x: number; y: number } | number[], limiter?: Function): Sprite[];
2901
+
2902
+ /**
2903
+ * Finds the first sprite (with a physics body) that
2904
+ * intersects a swept circle (capsule cast) from startPos to endPos.
2905
+ *
2906
+ * @param startPos starting position of the cast, object with x and y properties or array [x, y]
2907
+ * @param endPos end position of the cast
2908
+ * @param radius radius of the circle
2909
+ * @returns The first sprite hit or undefined
2910
+ */
2911
+ circleCast(startPos: { x: number; y: number } | number[], endPos: { x: number; y: number } | number[], radius: number): Sprite;
2912
+
2913
+ /**
2914
+ * Finds all sprites (with physics bodies) that intersect
2915
+ * a swept circle (capsule cast) from startPos to endPos, sorted by distance.
2916
+ *
2917
+ * @param startPos starting position of the cast
2918
+ * @param endPos end position of the cast
2919
+ * @param radius radius of the circle
2920
+ * @param limiter callback run each time the cast hits a sprite; return true to stop the cast
2921
+ * @returns An array of sprites hit, sorted by distance.
2922
+ */
2923
+ circleCastAll(startPos: { x: number; y: number } | number[], endPos: { x: number; y: number } | number[], radius: number, limiter?: Function): Sprite[];
2924
+
1940
2925
  /**
1941
2926
  * Applies an explosive force to sprites within the radius of the explosion.
1942
2927
  *
1943
- * @param x x coordinate or coordinate array or object with x and y properties of the center of the explosion
2928
+ * @param x x coordinate or object with x and y properties of the center of the explosion
1944
2929
  * @param y
1945
2930
  * @param radius the distance from the center of the explosion that sprites can be affected by the explosion
1946
2931
  * @param magnitude the strength of the explosion force, default is 1
1947
2932
  * @param falloff how much the explosion force decreases as sprites are farther from the center of the explosion, default is 0.1 (10% decrease per pixel)
1948
2933
  */
1949
- explodeAt(x: number | any, y?: number, radius?: number, magnitude?: number, falloff?: number): void;
2934
+ explodeAt(x: number, y: number, radius?: number, magnitude?: number, falloff?: number): void;
2935
+ explodeAt(pos: { x: number; y: number }, radius?: number, magnitude?: number, falloff?: number): void;
2936
+
2937
+ /**
2938
+ * The number of physics bodies currently awake in the world.
2939
+ * @readonly
2940
+ */
2941
+ get awakeBodies(): number;
2942
+
2943
+ /**
2944
+ * The minimum impact velocity needed for a hit event to be fired.
2945
+ */
2946
+ get hitThreshold(): number;
2947
+ set hitThreshold(val: number);
2948
+
2949
+ /**
2950
+ * Box2D world performance profile data.
2951
+ * @readonly
2952
+ */
2953
+ get profile(): any;
2954
+
2955
+ /**
2956
+ * Box2D world counter/statistics data.
2957
+ * @readonly
2958
+ */
2959
+ get debugInfo(): any;
2960
+
2961
+ /**
2962
+ * The number of sub-steps per physics update.
2963
+ * More sub-steps increases accuracy at the cost of performance.
2964
+ * @default 4
2965
+ */
2966
+ subSteps: number;
2967
+
2968
+ /**
2969
+ * Alias for `physicsUpdate`.
2970
+ */
2971
+ step(timeStep?: number): void;
2972
+
2973
+ /**
2974
+ * The Box2D world ID. Don't change it!
2975
+ */
2976
+ wID: b2WorldId;
1950
2977
  }
1951
2978
 
2979
+ /**
2980
+ * The Camera controls the position and zoom of the view of the world that is drawn on the canvas.
2981
+ */
1952
2982
  class Camera {
1953
2983
  /**
1954
2984
  * Read only. True if the camera is active.
@@ -1956,26 +2986,37 @@ declare global {
1956
2986
  * @default false
1957
2987
  */
1958
2988
  isActive: boolean;
1959
- /**
1960
- * The camera's position. {x, y}
1961
- */
1962
- get pos(): any;
1963
- set pos(val: any);
2989
+
1964
2990
  /**
1965
2991
  * The camera's x position.
1966
2992
  */
1967
2993
  get x(): number;
1968
2994
  set x(val: number);
2995
+
1969
2996
  /**
1970
2997
  * The camera's y position.
1971
2998
  */
1972
2999
  get y(): number;
1973
3000
  set y(val: number);
3001
+
3002
+ /**
3003
+ * Gets the camera's position as a readonly {x, y} object that
3004
+ * won't be updated if the camera moves. Useful for saving the
3005
+ * camera's position at a specific moment in time.
3006
+ */
3007
+ get pos(): { x: number; y: number };
3008
+
3009
+ /**
3010
+ * The camera's position.
3011
+ */
3012
+ set pos(val: number[] | { x: number; y: number });
3013
+
1974
3014
  /**
1975
- * The camera's position. Alias for pos.
3015
+ * The camera's position vector.
1976
3016
  */
1977
- get position(): any;
1978
- set position(val: any);
3017
+ get position(): Q5.Vector;
3018
+ set position(val: number[] | { x: number; y: number });
3019
+
1979
3020
  /**
1980
3021
  * Moves the camera to a position.
1981
3022
  *
@@ -1985,6 +3026,7 @@ declare global {
1985
3026
  * @returns resolves true when the camera reaches the target position
1986
3027
  */
1987
3028
  moveTo(x: number, y: number, speed: number): Promise<boolean>;
3029
+
1988
3030
  /**
1989
3031
  * Camera zoom.
1990
3032
  *
@@ -1995,6 +3037,7 @@ declare global {
1995
3037
  */
1996
3038
  get zoom(): number;
1997
3039
  set zoom(val: number);
3040
+
1998
3041
  /**
1999
3042
  * Zoom the camera at a given speed.
2000
3043
  *
@@ -2003,6 +3046,7 @@ declare global {
2003
3046
  * @returns resolves true when the camera reaches the target zoom
2004
3047
  */
2005
3048
  zoomTo(target: number, speed: number): Promise<boolean>;
3049
+
2006
3050
  /**
2007
3051
  * Activates the camera.
2008
3052
  *
@@ -2010,6 +3054,7 @@ declare global {
2010
3054
  * camera.off() is called.
2011
3055
  */
2012
3056
  on(): void;
3057
+
2013
3058
  /**
2014
3059
  * Deactivates the camera.
2015
3060
  *
@@ -2019,11 +3064,12 @@ declare global {
2019
3064
  off(): void;
2020
3065
  }
2021
3066
 
3067
+ /**
3068
+ * A Joint is used to constrain the movement of two sprites relative
3069
+ * to each other, which can lead to nuanced physics interactions.
3070
+ */
2022
3071
  class Joint {
2023
3072
  /**
2024
- * Joints are used to constrain the movement of two sprites relative
2025
- * to each other. They can be used to create complex physics objects.
2026
- *
2027
3073
  * Don't use the Joint constructor directly, use one of these
2028
3074
  * joint constructors instead:
2029
3075
  *
@@ -2035,14 +3081,17 @@ declare global {
2035
3081
  * @param type
2036
3082
  */
2037
3083
  constructor(spriteA: Sprite, spriteB: Sprite, type?: string);
3084
+
2038
3085
  /**
2039
3086
  * The first sprite in the joint.
2040
3087
  */
2041
3088
  spriteA: Sprite;
3089
+
2042
3090
  /**
2043
3091
  * The second sprite in the joint.
2044
3092
  */
2045
3093
  spriteB: Sprite;
3094
+
2046
3095
  /**
2047
3096
  * The type of joint. Can be one of:
2048
3097
  *
@@ -2051,12 +3100,14 @@ declare global {
2051
3100
  * Can't be changed after the joint is created.
2052
3101
  */
2053
3102
  type: string;
3103
+
2054
3104
  /**
2055
3105
  * Determines whether to draw the joint if spriteA
2056
3106
  * or spriteB is drawn.
2057
3107
  * @default true
2058
3108
  */
2059
3109
  visible: boolean;
3110
+
2060
3111
  /**
2061
3112
  * Offset to the joint's anchorA position from the center of spriteA.
2062
3113
  *
@@ -2064,7 +3115,8 @@ declare global {
2064
3115
  * @default {x: 0, y: 0}
2065
3116
  */
2066
3117
  get offsetA(): Q5.Vector;
2067
- set offsetA(val: Q5.Vector);
3118
+ set offsetA(val: [] | { x: number; y: number } | Q5.Vector);
3119
+
2068
3120
  /**
2069
3121
  * Offset to the joint's anchorB position from the center of spriteB.
2070
3122
  *
@@ -2072,12 +3124,14 @@ declare global {
2072
3124
  * @default {x: 0, y: 0}
2073
3125
  */
2074
3126
  get offsetB(): Q5.Vector;
2075
- set offsetB(val: Q5.Vector);
3127
+ set offsetB(val: [] | { x: number; y: number } | Q5.Vector);
3128
+
2076
3129
  /**
2077
3130
  * Function that draws the joint. Can be overridden by the user.
2078
3131
  */
2079
3132
  get draw(): Function;
2080
3133
  set draw(val: Function);
3134
+
2081
3135
  /**
2082
3136
  * Set to true if you want the joint's sprites to collide with
2083
3137
  * each other.
@@ -2085,16 +3139,19 @@ declare global {
2085
3139
  */
2086
3140
  get collideConnected(): boolean;
2087
3141
  set collideConnected(val: boolean);
3142
+
2088
3143
  /**
2089
3144
  * How much force the joint is applying to keep the two sprites together.
2090
3145
  * @readonly
2091
3146
  */
2092
3147
  get reactionForce(): any;
3148
+
2093
3149
  /**
2094
3150
  * How much torque the joint is applying to keep the two sprites together.
2095
3151
  * @readonly
2096
3152
  */
2097
3153
  get reactionTorque(): any;
3154
+
2098
3155
  /**
2099
3156
  * The amount of force that must be applied to the joint before it breaks.
2100
3157
  *
@@ -2104,6 +3161,7 @@ declare global {
2104
3161
  */
2105
3162
  get forceThreshold(): number;
2106
3163
  set forceThreshold(val: number);
3164
+
2107
3165
  /**
2108
3166
  * The amount of torque that must be applied to the joint before it breaks.
2109
3167
  *
@@ -2113,6 +3171,7 @@ declare global {
2113
3171
  */
2114
3172
  get torqueThreshold(): number;
2115
3173
  set torqueThreshold(val: number);
3174
+
2116
3175
  /**
2117
3176
  * This function is run when the joint's reaction force exceeds the
2118
3177
  * force threshold or its reaction torque exceeds the torque threshold.
@@ -2121,11 +3180,17 @@ declare global {
2121
3180
  * and the joint is deleted, simulating a break.
2122
3181
  */
2123
3182
  onStrain(): void;
3183
+
2124
3184
  /**
2125
3185
  * Deletes the joint from the world and from each of the
2126
3186
  * associated sprites' joints arrays.
2127
3187
  */
2128
3188
  delete(): void;
3189
+
3190
+ /**
3191
+ * The Box2D joint ID. Don't change it!
3192
+ */
3193
+ jID: b2JointId;
2129
3194
  }
2130
3195
 
2131
3196
  class GlueJoint extends Joint {
@@ -2151,11 +3216,13 @@ declare global {
2151
3216
  * @param spriteB
2152
3217
  */
2153
3218
  constructor(spriteA: Sprite, spriteB: Sprite);
3219
+
2154
3220
  /**
2155
3221
  * The current distance between the two joint anchors.
2156
3222
  * @readonly
2157
3223
  */
2158
3224
  get currentLength(): number;
3225
+
2159
3226
  /**
2160
3227
  * The target length of the joint between the two joint anchors.
2161
3228
  *
@@ -2164,6 +3231,7 @@ declare global {
2164
3231
  */
2165
3232
  get length(): number;
2166
3233
  set length(val: number);
3234
+
2167
3235
  /**
2168
3236
  * Whether the joint's length limits are enabled.
2169
3237
  * When enabled a min/max length range constrains the joint.
@@ -2171,27 +3239,32 @@ declare global {
2171
3239
  */
2172
3240
  get limitsEnabled(): boolean;
2173
3241
  set limitsEnabled(val: boolean);
3242
+
2174
3243
  /**
2175
3244
  * The minimum length allowed when limits are enabled.
2176
3245
  * @readonly
2177
3246
  */
2178
3247
  get minLength(): number;
3248
+
2179
3249
  /**
2180
3250
  * The maximum length allowed when limits are enabled.
2181
3251
  * @readonly
2182
3252
  */
2183
3253
  get maxLength(): number;
3254
+
2184
3255
  /**
2185
3256
  * Accepts a number to set a symmetric range
2186
3257
  * or an array with the minimum and maximum length limits.
2187
3258
  */
2188
3259
  set range(val: [number, number] | number);
3260
+
2189
3261
  /**
2190
3262
  * Whether spring behavior is enabled for the joint.
2191
3263
  * @default true
2192
3264
  */
2193
3265
  get springEnabled(): boolean;
2194
3266
  set springEnabled(val: boolean);
3267
+
2195
3268
  /**
2196
3269
  * The springiness of the joint, a 0-1 ratio.
2197
3270
  *
@@ -2200,6 +3273,7 @@ declare global {
2200
3273
  */
2201
3274
  get springiness(): number;
2202
3275
  set springiness(val: number);
3276
+
2203
3277
  /**
2204
3278
  * Damping is a 0-1 ratio describing how quickly the joint loses
2205
3279
  * vibrational energy.
@@ -2213,23 +3287,27 @@ declare global {
2213
3287
  */
2214
3288
  get damping(): number;
2215
3289
  set damping(val: number);
3290
+
2216
3291
  /**
2217
3292
  * Whether the joint's motor is enabled.
2218
3293
  * @default false
2219
3294
  */
2220
3295
  get motorEnabled(): boolean;
2221
3296
  set motorEnabled(val: boolean);
3297
+
2222
3298
  /**
2223
3299
  * Motor speed.
2224
3300
  * @default 0
2225
3301
  */
2226
3302
  get speed(): number;
2227
3303
  set speed(val: number);
3304
+
2228
3305
  /**
2229
3306
  * Maximum motor force the motor can apply.
2230
3307
  */
2231
3308
  get maxPower(): number;
2232
3309
  set maxPower(val: number);
3310
+
2233
3311
  /**
2234
3312
  * The current motor force being applied by the joint.
2235
3313
  * @readonly
@@ -2248,6 +3326,7 @@ declare global {
2248
3326
  * @param spriteB the wheel
2249
3327
  */
2250
3328
  constructor(spriteA: Sprite, spriteB: Sprite);
3329
+
2251
3330
  /**
2252
3331
  * The angle at which the wheel is attached to the vehicle body.
2253
3332
  *
@@ -2256,6 +3335,7 @@ declare global {
2256
3335
  */
2257
3336
  get angle(): number;
2258
3337
  set angle(val: number);
3338
+
2259
3339
  /**
2260
3340
  * Whether the joint's suspension limits are enabled.
2261
3341
  * When enabled a min/max distance from resting constrains the joint.
@@ -2263,6 +3343,7 @@ declare global {
2263
3343
  */
2264
3344
  get limitsEnabled(): boolean;
2265
3345
  set limitsEnabled(val: boolean);
3346
+
2266
3347
  /**
2267
3348
  * The minimum distance the wheel's suspension can contract
2268
3349
  * from 0, which represents the resting position,
@@ -2270,6 +3351,7 @@ declare global {
2270
3351
  * @readonly
2271
3352
  */
2272
3353
  get lowerLimit(): number;
3354
+
2273
3355
  /**
2274
3356
  * The maximum distance the wheel's suspension can extend
2275
3357
  * from 0, which represents the resting position,
@@ -2277,6 +3359,7 @@ declare global {
2277
3359
  * @readonly
2278
3360
  */
2279
3361
  get upperLimit(): number;
3362
+
2280
3363
  /**
2281
3364
  * The distance the wheel's suspension can contract or extend
2282
3365
  * from 0, which represents the resting position.
@@ -2285,6 +3368,7 @@ declare global {
2285
3368
  * or an array with the minimum and maximum length limits.
2286
3369
  */
2287
3370
  set range(val: [number, number] | number);
3371
+
2288
3372
  /**
2289
3373
  * Whether the wheel joint has suspension,
2290
3374
  * which can make it ride smoother over bumps.
@@ -2292,6 +3376,7 @@ declare global {
2292
3376
  */
2293
3377
  get springEnabled(): boolean;
2294
3378
  set springEnabled(val: boolean);
3379
+
2295
3380
  /**
2296
3381
  * The springiness of the joint, a 0-1 ratio.
2297
3382
  *
@@ -2300,6 +3385,7 @@ declare global {
2300
3385
  */
2301
3386
  get springiness(): number;
2302
3387
  set springiness(val: number);
3388
+
2303
3389
  /**
2304
3390
  * Damping is a 0-1 ratio describing how quickly the joint loses
2305
3391
  * vibrational energy.
@@ -2313,23 +3399,27 @@ declare global {
2313
3399
  */
2314
3400
  get damping(): number;
2315
3401
  set damping(val: number);
3402
+
2316
3403
  /**
2317
3404
  * Whether the joint's motor is enabled.
2318
3405
  * @default false
2319
3406
  */
2320
3407
  get motorEnabled(): boolean;
2321
3408
  set motorEnabled(val: boolean);
3409
+
2322
3410
  /**
2323
3411
  * Motor speed.
2324
3412
  * @default 0
2325
3413
  */
2326
3414
  get speed(): number;
2327
3415
  set speed(val: number);
3416
+
2328
3417
  /**
2329
3418
  * Maximum torque the motor can apply.
2330
3419
  */
2331
3420
  get maxPower(): number;
2332
3421
  set maxPower(val: number);
3422
+
2333
3423
  /**
2334
3424
  * The current torque being applied by the motor.
2335
3425
  * @readonly
@@ -2348,6 +3438,7 @@ declare global {
2348
3438
  * @param spriteB
2349
3439
  */
2350
3440
  constructor(spriteA: Sprite, spriteB: Sprite);
3441
+
2351
3442
  /**
2352
3443
  * Whether the joint's angle limits are enabled.
2353
3444
  * When enabled a min/max angle range constrains the joint.
@@ -2355,32 +3446,38 @@ declare global {
2355
3446
  */
2356
3447
  get limitsEnabled(): boolean;
2357
3448
  set limitsEnabled(val: boolean);
3449
+
2358
3450
  /**
2359
3451
  * The lower limit of rotation.
2360
3452
  * @readonly
2361
3453
  */
2362
3454
  get minAngle(): number;
3455
+
2363
3456
  /**
2364
3457
  * The upper limit of rotation.
2365
3458
  * @readonly
2366
3459
  */
2367
3460
  get maxAngle(): number;
3461
+
2368
3462
  /**
2369
3463
  * Accepts a number to set a symmetric range
2370
3464
  * or an array with the lower and upper limits of rotation.
2371
3465
  */
2372
3466
  set range(val: [number, number] | number);
3467
+
2373
3468
  /**
2374
3469
  * The joint's current angle of rotation.
2375
3470
  * @readonly
2376
3471
  */
2377
3472
  get angle(): number;
3473
+
2378
3474
  /**
2379
3475
  * Whether spring behavior is enabled.
2380
3476
  * @default false
2381
3477
  */
2382
3478
  get springEnabled(): boolean;
2383
3479
  set springEnabled(val: boolean);
3480
+
2384
3481
  /**
2385
3482
  * The springiness of the joint, a 0-1 ratio.
2386
3483
  *
@@ -2389,29 +3486,34 @@ declare global {
2389
3486
  */
2390
3487
  get springiness(): number;
2391
3488
  set springiness(val: number);
3489
+
2392
3490
  /**
2393
3491
  * Damping ratio, 0-1. Higher values reduce oscillation faster.
2394
3492
  * @default 0
2395
3493
  */
2396
3494
  get damping(): number;
2397
3495
  set damping(val: number);
3496
+
2398
3497
  /**
2399
3498
  * Whether the joint's motor is enabled.
2400
3499
  * @default false
2401
3500
  */
2402
3501
  get motorEnabled(): boolean;
2403
3502
  set motorEnabled(val: boolean);
3503
+
2404
3504
  /**
2405
3505
  * Motor speed.
2406
3506
  * @default 0
2407
3507
  */
2408
3508
  get speed(): number;
2409
3509
  set speed(val: number);
3510
+
2410
3511
  /**
2411
3512
  * Maximum torque the motor can apply.
2412
3513
  */
2413
3514
  get maxPower(): number;
2414
3515
  set maxPower(val: number);
3516
+
2415
3517
  /**
2416
3518
  * The current torque being applied by the motor.
2417
3519
  * @readonly
@@ -2430,38 +3532,45 @@ declare global {
2430
3532
  * @param spriteB
2431
3533
  */
2432
3534
  constructor(spriteA: Sprite, spriteB: Sprite);
3535
+
2433
3536
  /**
2434
3537
  * The current displacement of spriteB along the slide axis.
2435
3538
  * @readonly
2436
3539
  */
2437
3540
  get translation(): number;
3541
+
2438
3542
  /**
2439
3543
  * Whether the joint's translation limits are enabled.
2440
3544
  * @default false
2441
3545
  */
2442
3546
  get limitsEnabled(): boolean;
2443
3547
  set limitsEnabled(val: boolean);
3548
+
2444
3549
  /**
2445
3550
  * The mathematical lower limit of translation.
2446
3551
  * @readonly
2447
3552
  */
2448
3553
  get lowerLimit(): number;
3554
+
2449
3555
  /**
2450
3556
  * The mathematical upper limit of translation.
2451
3557
  * @readonly
2452
3558
  */
2453
3559
  get upperLimit(): number;
3560
+
2454
3561
  /**
2455
3562
  * Accepts a number to set a symmetric range
2456
3563
  * or an array with the lower and upper translation limits.
2457
3564
  */
2458
3565
  set range(val: [number, number] | number);
3566
+
2459
3567
  /**
2460
3568
  * Whether spring behavior is enabled.
2461
3569
  * @default false
2462
3570
  */
2463
3571
  get springEnabled(): boolean;
2464
3572
  set springEnabled(val: boolean);
3573
+
2465
3574
  /**
2466
3575
  * The springiness of the joint, a 0-1 ratio.
2467
3576
  *
@@ -2470,35 +3579,41 @@ declare global {
2470
3579
  */
2471
3580
  get springiness(): number;
2472
3581
  set springiness(val: number);
3582
+
2473
3583
  /**
2474
3584
  * Damping ratio, 0-1. Higher values reduce oscillation faster.
2475
3585
  * @default 0
2476
3586
  */
2477
3587
  get damping(): number;
2478
3588
  set damping(val: number);
3589
+
2479
3590
  /**
2480
3591
  * Whether the joint's motor is enabled.
2481
3592
  * @default true
2482
3593
  */
2483
3594
  get motorEnabled(): boolean;
2484
3595
  set motorEnabled(val: boolean);
3596
+
2485
3597
  /**
2486
3598
  * Motor speed.
2487
3599
  * @default 0
2488
3600
  */
2489
3601
  get speed(): number;
2490
3602
  set speed(val: number);
3603
+
2491
3604
  /**
2492
3605
  * Maximum force the motor can apply.
2493
3606
  * @default 10
2494
3607
  */
2495
3608
  get maxPower(): number;
2496
3609
  set maxPower(val: number);
3610
+
2497
3611
  /**
2498
3612
  * The current motor force being applied.
2499
3613
  * @readonly
2500
3614
  */
2501
3615
  get power(): number;
3616
+
2502
3617
  /**
2503
3618
  * The current sliding speed of the joint.
2504
3619
  * @readonly
@@ -2515,16 +3630,19 @@ declare global {
2515
3630
  * @param sprite the sprite to grab
2516
3631
  */
2517
3632
  constructor(pointer: any, sprite: Sprite);
3633
+
2518
3634
  /**
2519
3635
  * The sprite being grabbed by the joint.
2520
3636
  */
2521
3637
  sprite: Sprite;
3638
+
2522
3639
  /**
2523
3640
  * The target position of the joint that the sprite will be
2524
3641
  * moved towards. Can be a coordinate array or object with x and y properties.
2525
3642
  */
2526
3643
  get target(): any;
2527
3644
  set target(pos: any);
3645
+
2528
3646
  /**
2529
3647
  * The maximum spring force that the joint can exert on the sprite.
2530
3648
  *
@@ -2532,6 +3650,7 @@ declare global {
2532
3650
  */
2533
3651
  get maxForce(): number;
2534
3652
  set maxForce(val: number);
3653
+
2535
3654
  /**
2536
3655
  * The maximum torque that the joint can exert on the sprite.
2537
3656
  *
@@ -2542,6 +3661,30 @@ declare global {
2542
3661
  set maxTorque(val: number);
2543
3662
  }
2544
3663
 
3664
+ class CastInfo {
3665
+ /**
3666
+ * The sprite that was hit by the ray or circle cast.
3667
+ */
3668
+ sprite: Sprite;
3669
+
3670
+ /**
3671
+ * The distance from the start of the cast to the intersection point.
3672
+ */
3673
+ distance: number;
3674
+
3675
+ /**
3676
+ * The intersection point of the cast with the sprite's shape.
3677
+ * @readonly
3678
+ */
3679
+ get intersect(): { x: number; y: number };
3680
+
3681
+ /**
3682
+ * The angle of incidence of the cast at the intersection point.
3683
+ * @readonly
3684
+ */
3685
+ get incidence(): number;
3686
+ }
3687
+
2545
3688
  class Scale {
2546
3689
  valueOf(): number;
2547
3690
  }
@@ -2566,16 +3709,19 @@ declare global {
2566
3709
  * @default 12
2567
3710
  */
2568
3711
  holdThreshold: number;
3712
+
2569
3713
  /**
2570
3714
  * @param inp
2571
3715
  * @returns true on the first frame that the user presses the input
2572
3716
  */
2573
3717
  presses(inp?: string): boolean;
3718
+
2574
3719
  /**
2575
3720
  * @param inp
2576
3721
  * @returns the amount of frames the user has been pressing the input
2577
3722
  */
2578
3723
  pressing(inp?: string): number;
3724
+
2579
3725
  /**
2580
3726
  * Same as the `released` function, which is preferred.
2581
3727
  * @deprecated
@@ -2583,21 +3729,25 @@ declare global {
2583
3729
  * @returns true on the first frame that the user released the input
2584
3730
  */
2585
3731
  pressed(inp?: string): boolean;
3732
+
2586
3733
  /**
2587
3734
  * @param inp
2588
3735
  * @returns true on the first frame that the user holds the input
2589
3736
  */
2590
3737
  holds(inp?: string): boolean;
3738
+
2591
3739
  /**
2592
3740
  * @param inp
2593
3741
  * @returns the amount of frames the user has been holding the input
2594
3742
  */
2595
3743
  holding(inp?: string): number;
3744
+
2596
3745
  /**
2597
3746
  * @param inp
2598
3747
  * @returns true on the first frame that the user released a held input
2599
3748
  */
2600
3749
  held(inp?: string): boolean;
3750
+
2601
3751
  /**
2602
3752
  * @param inp
2603
3753
  * @returns true on the first frame that the user released the input
@@ -2611,91 +3761,111 @@ declare global {
2611
3761
  * The mouse's x position in the world.
2612
3762
  */
2613
3763
  x: number;
3764
+
2614
3765
  /**
2615
3766
  * The mouse's y position in the world.
2616
3767
  */
2617
3768
  y: number;
3769
+
2618
3770
  /**
2619
3771
  * The mouse's absolute position on the canvas.
2620
3772
  * @property {Number} x
2621
3773
  * @property {Number} y
2622
3774
  */
2623
3775
  canvasPos: { x: number; y: number };
3776
+
2624
3777
  /**
2625
3778
  * The mouse's left button.
2626
3779
  */
2627
3780
  left: number;
3781
+
2628
3782
  /**
2629
3783
  * The mouse's center button.
2630
3784
  */
2631
3785
  center: number;
3786
+
2632
3787
  /**
2633
3788
  * The mouse's right button.
2634
3789
  */
2635
3790
  right: number;
3791
+
2636
3792
  /**
2637
3793
  * Contains the scroll status of the mouse wheel.
2638
3794
  * @property {Number} x the horizontal scroll amount
2639
3795
  * @property {Number} y the vertical scroll amount
2640
3796
  */
2641
3797
  scrollDelta: { x: number; y: number };
3798
+
2642
3799
  /**
2643
3800
  * Contains the drag status of each of the mouse's buttons.
2644
3801
  */
2645
3802
  drag: {};
3803
+
2646
3804
  /**
2647
3805
  * True if the mouse is currently on the canvas.
2648
3806
  * @default false
2649
3807
  */
2650
3808
  isOnCanvas: boolean;
3809
+
2651
3810
  /**
2652
3811
  * True if the mouse has ever interacted with the canvas.
2653
3812
  * @default false
2654
3813
  */
2655
3814
  isActive: boolean;
3815
+
2656
3816
  /**
2657
- * The mouse's position.
3817
+ * Gets the mouse's current position in the world as a readonly object {x, y}
3818
+ * that won't updated if the mouse moves.
2658
3819
  */
2659
- get pos(): {};
3820
+ get pos(): { x: number; y: number };
3821
+
2660
3822
  /**
2661
- * The mouse's position. Alias for pos.
3823
+ * The mouse's current position.
2662
3824
  */
2663
- get position(): {};
3825
+ get position(): { x: number; y: number };
3826
+
2664
3827
  /**
2665
3828
  * The mouse's CSS cursor style.
2666
3829
  * @default 'default'
2667
3830
  */
2668
3831
  get cursor(): string;
2669
3832
  set cursor(val: string);
3833
+
2670
3834
  /**
2671
3835
  * Controls whether the mouse is visible or not.
2672
3836
  * @default true
2673
3837
  */
2674
3838
  get visible(): boolean;
2675
3839
  set visible(val: boolean);
3840
+
2676
3841
  /**
2677
3842
  * @param inp
2678
3843
  * @returns true on the first frame that the user moves the mouse while pressing the input
2679
3844
  */
2680
3845
  drags(inp?: string): boolean;
3846
+
2681
3847
  /**
2682
3848
  * @param inp
2683
3849
  * @returns the amount of frames the user has been moving the mouse while pressing the input
2684
3850
  */
2685
3851
  dragging(inp?: string): number;
3852
+
2686
3853
  /**
2687
3854
  * @param inp
2688
3855
  * @returns true on the first frame that the user releases the input after dragging the mouse
2689
3856
  */
2690
3857
  dragged(inp?: string): boolean;
3858
+
2691
3859
  /**
2692
3860
  * @returns true on the first frame that the user scrolls the mouse wheel
2693
3861
  */
2694
3862
  scrolls(): boolean;
3863
+
2695
3864
  /**
2696
3865
  * @returns the amount of frames the user has been scrolling the mouse wheel
2697
3866
  */
2698
3867
  scrolling(): number;
3868
+
2699
3869
  /**
2700
3870
  * @returns true on the first frame that the user stops scrolling the mouse wheel
2701
3871
  */
@@ -2704,26 +3874,32 @@ declare global {
2704
3874
 
2705
3875
  class _Pointer extends InputDevice {
2706
3876
  constructor(pointer: any);
3877
+
2707
3878
  /**
2708
3879
  * The pointer's x position in the physics world.
2709
3880
  */
2710
3881
  x: number;
3882
+
2711
3883
  /**
2712
3884
  * The pointer's y position in the physics world.
2713
3885
  */
2714
3886
  y: number;
3887
+
2715
3888
  /**
2716
3889
  * The pointer's unique identifier.
2717
3890
  */
2718
3891
  id: number;
3892
+
2719
3893
  /**
2720
3894
  * The amount of frames the pointer has been active for.
2721
3895
  */
2722
3896
  duration: number;
3897
+
2723
3898
  /**
2724
3899
  * The pointer's absolute position on the canvas.
2725
3900
  */
2726
3901
  canvasPos: { x: number; y: number };
3902
+
2727
3903
  /**
2728
3904
  * The pointer's pressure level, from 0 to 1.
2729
3905
  *
@@ -2731,33 +3907,40 @@ declare global {
2731
3907
  * the value is 0.5 when the pointer is pressing.
2732
3908
  */
2733
3909
  pressure: number;
3910
+
2734
3911
  /**
2735
3912
  * The amount of frames the user has been clicking, touching,
2736
3913
  * or drawing on the screen with the pointer.
2737
3914
  */
2738
3915
  press: number;
3916
+
2739
3917
  /**
2740
3918
  * @returns true on the first frame that the pointer grabs a sprite
2741
3919
  */
2742
3920
  grabs(): boolean;
3921
+
2743
3922
  /**
2744
3923
  * @returns the amount of frames the pointer has been grabbing a sprite
2745
3924
  */
2746
3925
  grabbing(): number;
3926
+
2747
3927
  /**
2748
3928
  * @returns true on the first frame that the pointer releases a grabbed sprite
2749
3929
  */
2750
3930
  grabbed(): boolean;
3931
+
2751
3932
  /**
2752
3933
  * @param sprite
2753
3934
  * @returns true on the first frame that the pointer overlaps the sprite
2754
3935
  */
2755
3936
  overlaps(sprite: Sprite): boolean;
3937
+
2756
3938
  /**
2757
3939
  * @param sprite
2758
3940
  * @returns the amount of frames the pointer has been overlapping the sprite
2759
3941
  */
2760
3942
  overlapping(sprite: Sprite): number;
3943
+
2761
3944
  /**
2762
3945
  * @param sprite
2763
3946
  * @returns true on the first frame that the pointer stops overlapping the sprite
@@ -2805,29 +3988,35 @@ declare global {
2805
3988
  b: number;
2806
3989
  x: number;
2807
3990
  y: number;
3991
+
2808
3992
  /**
2809
3993
  * Left shoulder button.
2810
3994
  */
2811
3995
  l: number;
3996
+
2812
3997
  /**
2813
3998
  * Right shoulder button.
2814
3999
  */
2815
4000
  r: number;
4001
+
2816
4002
  /**
2817
4003
  * Digital left trigger.
2818
4004
  */
2819
4005
  lt: number;
4006
+
2820
4007
  /**
2821
4008
  * Digital right trigger.
2822
4009
  */
2823
4010
  rt: number;
2824
4011
  select: number;
2825
4012
  start: number;
4013
+
2826
4014
  /**
2827
4015
  * Left stick button.
2828
4016
  * Activated by pressing down on the left analog stick.
2829
4017
  */
2830
4018
  lsb: number;
4019
+
2831
4020
  /**
2832
4021
  * Right stick button.
2833
4022
  * Activated by pressing down on the right analog stick.
@@ -2837,6 +4026,7 @@ declare global {
2837
4026
  down: number;
2838
4027
  left: number;
2839
4028
  right: number;
4029
+
2840
4030
  /**
2841
4031
  * Has x and y properties with -1 to 1 values which
2842
4032
  * represent the position of the left analog stick.
@@ -2844,6 +4034,7 @@ declare global {
2844
4034
  * {x: 0, y: 0} is the center position.
2845
4035
  */
2846
4036
  leftStick: any;
4037
+
2847
4038
  /**
2848
4039
  * Has x and y properties with -1 to 1 values which
2849
4040
  * represent the position of the right analog stick.
@@ -2851,30 +4042,36 @@ declare global {
2851
4042
  * {x: 0, y: 0} is the center position.
2852
4043
  */
2853
4044
  rightStick: any;
4045
+
2854
4046
  /**
2855
4047
  * Analog value 0-1 of the left trigger.
2856
4048
  * @default 0
2857
4049
  */
2858
4050
  leftTrigger: number;
4051
+
2859
4052
  /**
2860
4053
  * Analog value 0-1 of the right trigger.
2861
4054
  * @default 0
2862
4055
  */
2863
4056
  rightTrigger: number;
4057
+
2864
4058
  /**
2865
4059
  * Button names are mapped to `gamepad.buttons` indices.
2866
4060
  */
2867
4061
  buttonMapping: any;
4062
+
2868
4063
  /**
2869
4064
  * Sticks and triggers are mapped to `gamepad.axes` indices.
2870
4065
  */
2871
4066
  axeMapping: any;
4067
+
2872
4068
  /**
2873
4069
  * If the controller is a mock controller.
2874
4070
  */
2875
4071
  isMock: boolean;
2876
4072
  gamepad: Gamepad;
2877
4073
  id: any;
4074
+
2878
4075
  /**
2879
4076
  * True if the controller has analog triggers.
2880
4077
  * False if the controller has digital (button) triggers.
@@ -2884,67 +4081,81 @@ declare global {
2884
4081
  get circle(): number;
2885
4082
  get square(): number;
2886
4083
  get triangle(): number;
4084
+
2887
4085
  /**
2888
4086
  * Alias for `leftStick`.
2889
4087
  */
2890
4088
  get ls(): any;
4089
+
2891
4090
  /**
2892
4091
  * Alias for `rightStick`.
2893
4092
  */
2894
4093
  get rs(): any;
4094
+
2895
4095
  /**
2896
4096
  * Alias for `l` (left shoulder button).
2897
4097
  * `lb` is what it's called on Xbox controllers.
2898
4098
  */
2899
4099
  get lb(): number;
4100
+
2900
4101
  /**
2901
4102
  * Alias for `r` (right shoulder button).
2902
4103
  * `rb` is what it's called on Xbox controllers.
2903
4104
  */
2904
4105
  get rb(): number;
4106
+
2905
4107
  /**
2906
4108
  * Alias for `l` (left shoulder button).
2907
4109
  * `l1` is what it's called on PlayStation controllers.
2908
4110
  */
2909
4111
  get l1(): number;
4112
+
2910
4113
  /**
2911
4114
  * Alias for `r` (right shoulder button).
2912
4115
  * `r1` is what it's called on PlayStation controllers.
2913
4116
  */
2914
4117
  get r1(): number;
4118
+
2915
4119
  /**
2916
4120
  * Alias for `lt` (digital left trigger).
2917
4121
  * `zl` is what it's called on Nintendo controllers.
2918
4122
  */
2919
4123
  get zl(): number;
4124
+
2920
4125
  /**
2921
4126
  * Alias for `rt` (digital right trigger).
2922
4127
  * `zr` is what it's called on Nintendo controllers.
2923
4128
  */
2924
4129
  get zr(): number;
4130
+
2925
4131
  /**
2926
4132
  * Alias for `leftTrigger` (analog left trigger).
2927
4133
  * `l2` is what it's called on PlayStation controllers.
2928
4134
  */
2929
4135
  get l2(): number;
4136
+
2930
4137
  /**
2931
4138
  * Alias for `rightTrigger` (analog right trigger).
2932
4139
  * `r2` is what it's called on PlayStation controllers.
2933
4140
  */
2934
4141
  get r2(): number;
4142
+
2935
4143
  /**
2936
4144
  * Verbose alias for `lsb`.
2937
4145
  */
2938
4146
  get leftStickButton(): number;
4147
+
2939
4148
  /**
2940
4149
  * Verbose alias for `rsb`.
2941
4150
  */
2942
4151
  get rightStickButton(): number;
4152
+
2943
4153
  /**
2944
4154
  * Alias for `lsb` (left stick button).
2945
4155
  * `l3` is what it's called on PlayStation controllers.
2946
4156
  */
2947
4157
  get l3(): number;
4158
+
2948
4159
  /**
2949
4160
  * Alias for `rsb` (right stick button).
2950
4161
  * `r3` is what it's called on PlayStation controllers.
@@ -2959,12 +4170,14 @@ declare global {
2959
4170
  * triggers, and sticks on game controllers.
2960
4171
  */
2961
4172
  constructor();
4173
+
2962
4174
  /**
2963
4175
  * Swap controller positions in this controllers array.
2964
4176
  * @param indexA
2965
4177
  * @param indexB
2966
4178
  */
2967
4179
  swap(indexA: number, indexB: number): void;
4180
+
2968
4181
  /**
2969
4182
  * Removes a controller from this controllers array
2970
4183
  * by setting `contros[index] = null`.
@@ -2973,6 +4186,7 @@ declare global {
2973
4186
  * @param index
2974
4187
  */
2975
4188
  remove(index: number): void;
4189
+
2976
4190
  /**
2977
4191
  * Runs when a controller is connected. By default it
2978
4192
  * always returns true. Overwrite this function to customize
@@ -2987,6 +4201,7 @@ declare global {
2987
4201
  * @returns true if the controller should be added to this q5play controllers array
2988
4202
  */
2989
4203
  onConnect(gamepad: Gamepad): boolean;
4204
+
2990
4205
  /**
2991
4206
  * Runs when a controller is disconnected. by default it
2992
4207
  * always returns false. Overwrite this function to customize
@@ -3002,10 +4217,20 @@ declare global {
3002
4217
  onDisconnect(gamepad: Gamepad): boolean;
3003
4218
  }
3004
4219
 
3005
- function colorPal(c: string, palette: number | any): string;
4220
+ function colorPal(c: string, palette: { [key: string]: string } | string[]): string;
3006
4221
  function EmojiImage(emoji: string, textSize: number): Q5.Image;
3007
- function spriteArt(txt: string, scale: number, palette: number | any): Q5.Image;
3008
- function animation(ani: Ani, x: number, y: number, r: number, sX: number, sY: number): void;
4222
+ function spriteArt(txt: string, scale: number, palette: { [key: string]: string } | string[]): Q5.Image;
4223
+
4224
+ /**
4225
+ * Draws an animation.
4226
+ * @param ani the animation
4227
+ * @param x x coordinate to draw the animation at
4228
+ * @param y y coordinate to draw the animation at
4229
+ * @param dW display width
4230
+ * @param dH display height
4231
+ */
4232
+ function animation(ani: Ani, x: number, y: number, dW: number, dH: number): void;
4233
+
3009
4234
  /**
3010
4235
  * @param milliseconds if not specified, delays until the next frame draw
3011
4236
  * @returns resolves after the delay