q5play 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Icon/r +0 -0
- package/LICENSE.md +74 -0
- package/README.md +39 -3
- package/package.json +22 -5
- package/q5play.d.ts +2924 -0
- package/q5play.js +8137 -1
package/q5play.d.ts
ADDED
|
@@ -0,0 +1,2924 @@
|
|
|
1
|
+
import 'q5';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
class Q5Play {
|
|
5
|
+
/**
|
|
6
|
+
* Contains all the sprites in the sketch.
|
|
7
|
+
*
|
|
8
|
+
* Users should use the `allSprites` group instead
|
|
9
|
+
* because this object includes deleted sprites.
|
|
10
|
+
*
|
|
11
|
+
* The keys are the sprite's unique ids.
|
|
12
|
+
*/
|
|
13
|
+
sprites: {
|
|
14
|
+
[key: number]: Sprite;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Contains all the groups in the sketch.
|
|
18
|
+
*
|
|
19
|
+
* The keys are the group's unique ids.
|
|
20
|
+
*/
|
|
21
|
+
groups: {
|
|
22
|
+
[key: number]: Group;
|
|
23
|
+
};
|
|
24
|
+
groupsCreated: number;
|
|
25
|
+
spritesCreated: number;
|
|
26
|
+
spritesDrawn: number;
|
|
27
|
+
/**
|
|
28
|
+
* The default color palette, at index 0 of this array,
|
|
29
|
+
* has all the letters of the English alphabet mapped to colors.
|
|
30
|
+
*/
|
|
31
|
+
palettes: any[];
|
|
32
|
+
/**
|
|
33
|
+
* Friendly rounding makes some Sprite getters return nice rounded numbers
|
|
34
|
+
* if a decimal value is within linear slop range (+/-0.005) or
|
|
35
|
+
* angular slop range (+/-0.000582 radians) of a whole number.
|
|
36
|
+
*
|
|
37
|
+
* This is because Box2D physics calculations can result in
|
|
38
|
+
* floating point drift, which beginners wouldn't expect.
|
|
39
|
+
*
|
|
40
|
+
* Setting to false can slightly improve performance.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
friendlyRounding: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Snaps sprites to the nearest `q5play.gridSize`
|
|
46
|
+
* increment when they are moved.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
snapToGrid: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The size of the grid cells that sprites are snapped to.
|
|
52
|
+
* @default 0.5
|
|
53
|
+
*/
|
|
54
|
+
gridSize: number;
|
|
55
|
+
/**
|
|
56
|
+
* Information about the operating system being used.
|
|
57
|
+
*/
|
|
58
|
+
os: {};
|
|
59
|
+
context: string;
|
|
60
|
+
hasMouse: boolean;
|
|
61
|
+
standardizeKeyboard: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Displays the version of q5play being used,
|
|
64
|
+
* the number of sprites being drawn
|
|
65
|
+
* and a realtime graphing of the current FPS.
|
|
66
|
+
*
|
|
67
|
+
* FPS in this context refers to how many frames per second your
|
|
68
|
+
* computer can generate, only based on the physics calculations and
|
|
69
|
+
* other processes necessary to generate a frame, but not
|
|
70
|
+
* including the delay between when frames are actually shown on
|
|
71
|
+
* the screen. The higher the FPS, the better your game is
|
|
72
|
+
* performing.
|
|
73
|
+
*
|
|
74
|
+
* You can use this function for approximate performance testing.
|
|
75
|
+
* But for the most accurate results, use your web browser's
|
|
76
|
+
* performance testing tools.
|
|
77
|
+
*
|
|
78
|
+
* Generally having less sprites and using a smaller canvas will
|
|
79
|
+
* make your game perform better. Also drawing images is faster
|
|
80
|
+
* than drawing shapes.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
renderStats: boolean;
|
|
84
|
+
}
|
|
85
|
+
const q5play: Q5Play;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Don't create Shapes directly; use `sprite.addCollider()`
|
|
89
|
+
* or `sprite.addSensor()` instead.
|
|
90
|
+
*/
|
|
91
|
+
class Shape {
|
|
92
|
+
sprite: Sprite;
|
|
93
|
+
type: string;
|
|
94
|
+
geom: any;
|
|
95
|
+
density: number;
|
|
96
|
+
scaleBy(scaleX: number, scaleY?: number): void;
|
|
97
|
+
delete(): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Colliders are added to a sprite's physics body to cause
|
|
102
|
+
* physical collisions with other sprites.
|
|
103
|
+
*
|
|
104
|
+
* Don't create Colliders directly; use Sprite.addCollider() instead.
|
|
105
|
+
*/
|
|
106
|
+
class Collider extends Shape {
|
|
107
|
+
friction: number;
|
|
108
|
+
bounciness: number;
|
|
109
|
+
density: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sensor are added to a sprite's physics body to detect overlaps
|
|
114
|
+
* without causing physical collisions.
|
|
115
|
+
*
|
|
116
|
+
* Don't create Sensors directly; use Sprite.addSensor() instead.
|
|
117
|
+
*
|
|
118
|
+
* @extends Shape
|
|
119
|
+
*/
|
|
120
|
+
class Sensor extends Shape {
|
|
121
|
+
_isSensor: boolean;
|
|
122
|
+
density: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Visual objects store images and animations that can be displayed
|
|
127
|
+
* with respect to the camera.
|
|
128
|
+
*/
|
|
129
|
+
class Visual {
|
|
130
|
+
/**
|
|
131
|
+
* Horizontal position of the visual.
|
|
132
|
+
*/
|
|
133
|
+
x: number;
|
|
134
|
+
/**
|
|
135
|
+
* Vertical position of the visual.
|
|
136
|
+
*/
|
|
137
|
+
y: number;
|
|
138
|
+
/**
|
|
139
|
+
* Horizontal velocity of the visual.
|
|
140
|
+
*/
|
|
141
|
+
vx: number;
|
|
142
|
+
/**
|
|
143
|
+
* Vertical velocity of the visual.
|
|
144
|
+
*/
|
|
145
|
+
vy: number;
|
|
146
|
+
/**
|
|
147
|
+
* Draws the visual on the canvas.
|
|
148
|
+
*/
|
|
149
|
+
draw(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Current image or frame of animation being displayed.
|
|
152
|
+
*/
|
|
153
|
+
get img(): Q5.Image;
|
|
154
|
+
set img(image: Q5.Image);
|
|
155
|
+
/**
|
|
156
|
+
* Current animation.
|
|
157
|
+
*/
|
|
158
|
+
get ani(): Ani;
|
|
159
|
+
set ani(val: Ani);
|
|
160
|
+
/**
|
|
161
|
+
* Stores animations.
|
|
162
|
+
* Keys are the animation label, values are Ani objects
|
|
163
|
+
*/
|
|
164
|
+
get anis(): Anis;
|
|
165
|
+
/**
|
|
166
|
+
* Adds an animation to the Sprite or Visual.
|
|
167
|
+
*
|
|
168
|
+
* @param spriteSheetURL the URL of the sprite sheet image
|
|
169
|
+
* @param frameCount the number of frames in the sprite sheet
|
|
170
|
+
* @returns A promise that fulfills when the animation is loaded
|
|
171
|
+
*/
|
|
172
|
+
addAni(spriteSheetURL: string, frameCount: number): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Add multiple animations to the Sprite or Visual.
|
|
175
|
+
*
|
|
176
|
+
* @param spriteSheetURL the URL of the sprite sheet image
|
|
177
|
+
* @param frameSize the size of each frame in the sprite sheet in the format "WIDTHxHEIGHT" (example: "32x32")
|
|
178
|
+
* @param atlases an object with animation names as keys and
|
|
179
|
+
* an animation or animation atlas as values
|
|
180
|
+
* @returns A promise that fulfills when the animations are loaded
|
|
181
|
+
*/
|
|
182
|
+
addAnis(spriteSheetURL?: string, frameSize?: string, atlases: {}): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Changes the sprite's animation. Use `addAni` to define the
|
|
185
|
+
* animation(s) first.
|
|
186
|
+
*
|
|
187
|
+
* @param name the name of the animation to switch to
|
|
188
|
+
*/
|
|
189
|
+
changeAni(name: string): void;
|
|
190
|
+
/**
|
|
191
|
+
* Plays an animation.
|
|
192
|
+
*
|
|
193
|
+
* You can put special modifier characters before the name:
|
|
194
|
+
* - "!" plays it backwards
|
|
195
|
+
* - ">" or "<" horizontally flips it
|
|
196
|
+
* - "^" vertically flips it
|
|
197
|
+
*
|
|
198
|
+
* @param name the name of the animation to play
|
|
199
|
+
* @returns A promise that fulfills when the animation completes
|
|
200
|
+
*/
|
|
201
|
+
playAni(name: string): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Plays a sequence of animations.
|
|
204
|
+
*
|
|
205
|
+
* You can put special modifier characters before each ani name:
|
|
206
|
+
* - "!" plays it backwards
|
|
207
|
+
* - ">" or "<" horizontally flips it
|
|
208
|
+
* - "^" vertically flips it
|
|
209
|
+
*
|
|
210
|
+
* You can put sequence modifiers at the end of the sequence:
|
|
211
|
+
* - "**" loops it indefinitely
|
|
212
|
+
* - ";;" stops it on the last ani's last frame
|
|
213
|
+
*
|
|
214
|
+
* @param sequence the names of animations
|
|
215
|
+
* @returns A promise that fulfills when the sequence completes
|
|
216
|
+
*/
|
|
217
|
+
playAnis(...sequence: string[]): Promise<void>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const DYNAMIC: 'dynamic';
|
|
221
|
+
const DYN: 'dynamic';
|
|
222
|
+
const STATIC: 'static';
|
|
223
|
+
const STA: 'static';
|
|
224
|
+
const KINEMATIC: 'kinematic';
|
|
225
|
+
const KIN: 'kinematic';
|
|
226
|
+
|
|
227
|
+
class Sprite extends Visual {
|
|
228
|
+
/**
|
|
229
|
+
* Creates a new sprite.
|
|
230
|
+
*
|
|
231
|
+
* Input parameters are optional. A sprite's default position is in the
|
|
232
|
+
* center of the canvas [0,0] and default box collider is 50x50 pixels.
|
|
233
|
+
*
|
|
234
|
+
* @param x horizontal position
|
|
235
|
+
* @param y vertical position
|
|
236
|
+
* @param w width of the collider
|
|
237
|
+
* @param h height of the collider
|
|
238
|
+
* @param physicsType physics type is DYNAMIC by default, can be
|
|
239
|
+
* STATIC or KINEMATIC
|
|
240
|
+
*/
|
|
241
|
+
constructor(x?: number, y?: number, w?: number, h?: number, physicsType?: string);
|
|
242
|
+
/**
|
|
243
|
+
* Creates a new sprite with an overlap sensor instead of a collider.
|
|
244
|
+
*
|
|
245
|
+
* @param x horizontal position
|
|
246
|
+
* @param y vertical position
|
|
247
|
+
* @param w width of the sensor
|
|
248
|
+
* @param h height of the sensor
|
|
249
|
+
* @param physicsType physics type is DYNAMIC by default, can be
|
|
250
|
+
* STATIC or KINEMATIC
|
|
251
|
+
*/
|
|
252
|
+
static withSensor(x?: number, y?: number, w?: number, h?: number, physicsType?: string): Sprite;
|
|
253
|
+
/**
|
|
254
|
+
* The physics type of the sprite, which determines how it interacts with
|
|
255
|
+
* other sprites in the physics simulation.
|
|
256
|
+
*
|
|
257
|
+
* It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
|
|
258
|
+
* @default "dynamic"
|
|
259
|
+
*/
|
|
260
|
+
get physics(): string;
|
|
261
|
+
set physics(val: string);
|
|
262
|
+
/**
|
|
263
|
+
* The physics type of the sprite, which determines how it interacts with
|
|
264
|
+
* other sprites in the physics simulation.
|
|
265
|
+
*
|
|
266
|
+
* It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
|
|
267
|
+
* @default "dynamic"
|
|
268
|
+
*/
|
|
269
|
+
get physicsType(): string;
|
|
270
|
+
set physicsType(val: string);
|
|
271
|
+
/**
|
|
272
|
+
* If true, the sprite's physics body is included in the physics simulation.
|
|
273
|
+
* @default true
|
|
274
|
+
*/
|
|
275
|
+
get physicsEnabled(): boolean;
|
|
276
|
+
set physicsEnabled(val: boolean);
|
|
277
|
+
/**
|
|
278
|
+
* Each sprite has a unique id number. Don't change it!
|
|
279
|
+
* They are useful for debugging.
|
|
280
|
+
*/
|
|
281
|
+
idNum: number;
|
|
282
|
+
/**
|
|
283
|
+
* Groups the sprite belongs to.
|
|
284
|
+
* @default [allSprites]
|
|
285
|
+
*/
|
|
286
|
+
groups: Group[];
|
|
287
|
+
/**
|
|
288
|
+
* Keys are the animation label, values are Ani objects.
|
|
289
|
+
*/
|
|
290
|
+
animations: Anis;
|
|
291
|
+
/**
|
|
292
|
+
* Array of colliders that are part of the sprite's physics body.
|
|
293
|
+
*/
|
|
294
|
+
colliders: Collider[];
|
|
295
|
+
/**
|
|
296
|
+
* Array of sensors that are part of the sprite's physics body.
|
|
297
|
+
* Sensors are used to detect overlaps without causing physical collisions.
|
|
298
|
+
*/
|
|
299
|
+
sensors: Sensor[];
|
|
300
|
+
/**
|
|
301
|
+
* Joints that the sprite is attached to.
|
|
302
|
+
* @default []
|
|
303
|
+
*/
|
|
304
|
+
joints: Joint[];
|
|
305
|
+
/**
|
|
306
|
+
* If set to true, q5play will record all changes to the sprite's
|
|
307
|
+
* properties in its `mod` array. Intended to be used to enable
|
|
308
|
+
* online multiplayer.
|
|
309
|
+
* @default undefined
|
|
310
|
+
*/
|
|
311
|
+
watch: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Modification tracking object.
|
|
314
|
+
*
|
|
315
|
+
* It has sprite property number codes as keys,
|
|
316
|
+
* these correspond to the index of the property in the
|
|
317
|
+
* Sprite.props array, and boolean values, that
|
|
318
|
+
* indicate which properties were changed since the last frame.
|
|
319
|
+
*
|
|
320
|
+
* Useful for limiting the amount of sprite data sent in netcode
|
|
321
|
+
* to only the sprite properties that have been modified.
|
|
322
|
+
*/
|
|
323
|
+
mod: {};
|
|
324
|
+
/**
|
|
325
|
+
* The horizontal position of the sprite.
|
|
326
|
+
*/
|
|
327
|
+
get x(): number;
|
|
328
|
+
set x(val: number);
|
|
329
|
+
/**
|
|
330
|
+
* The vertical position of the sprite.
|
|
331
|
+
*/
|
|
332
|
+
get y(): number;
|
|
333
|
+
set y(val: number);
|
|
334
|
+
/**
|
|
335
|
+
* The width of the sprite.
|
|
336
|
+
*/
|
|
337
|
+
get w(): number;
|
|
338
|
+
set w(val: number);
|
|
339
|
+
/**
|
|
340
|
+
* The height of the sprite.
|
|
341
|
+
*/
|
|
342
|
+
get h(): number;
|
|
343
|
+
set h(val: number);
|
|
344
|
+
/**
|
|
345
|
+
* The sprite's position on the previous frame.
|
|
346
|
+
*/
|
|
347
|
+
prevPos: {};
|
|
348
|
+
/**
|
|
349
|
+
* The sprite's rotation on the previous frame.
|
|
350
|
+
*/
|
|
351
|
+
prevRotation: number;
|
|
352
|
+
/**
|
|
353
|
+
* Text displayed at the center of the sprite.
|
|
354
|
+
* @default undefined
|
|
355
|
+
*/
|
|
356
|
+
text: string;
|
|
357
|
+
/**
|
|
358
|
+
* Adds a collider to the sprite's physics body.
|
|
359
|
+
*
|
|
360
|
+
* It accepts parameters in a similar format to the Sprite
|
|
361
|
+
* constructor except the first two parameters are x and y offsets,
|
|
362
|
+
* the distance new collider should be from the center of the sprite.
|
|
363
|
+
*
|
|
364
|
+
* This function also recalculates the sprite's mass based on the
|
|
365
|
+
* size of the new collider added to it. However, it does not move
|
|
366
|
+
* the sprite's center of mass, which makes adding multiple colliders
|
|
367
|
+
* to a sprite easier.
|
|
368
|
+
*
|
|
369
|
+
* @param offsetX distance from the center of the sprite
|
|
370
|
+
* @param offsetY distance from the center of the sprite
|
|
371
|
+
* @param w width of the collider
|
|
372
|
+
* @param h height of the collider
|
|
373
|
+
*/
|
|
374
|
+
addCollider(offsetX: number, offsetY: number, w?: number, h?: number): void;
|
|
375
|
+
/**
|
|
376
|
+
* Adds an overlap sensor to the sprite's physics body.
|
|
377
|
+
*
|
|
378
|
+
* Sensors can't displace or be displaced by colliders.
|
|
379
|
+
* Sensors don't have any mass or other physical properties.
|
|
380
|
+
* Sensors simply detect overlaps.
|
|
381
|
+
*
|
|
382
|
+
* This function accepts parameters in a similar format to the Sprite
|
|
383
|
+
* constructor except the first two parameters are x and y offsets,
|
|
384
|
+
* the relative distance the new sensor should be from the center of
|
|
385
|
+
* the sprite.
|
|
386
|
+
*
|
|
387
|
+
* @param offsetX distance from the center of the sprite
|
|
388
|
+
* @param offsetY distance from the center of the sprite
|
|
389
|
+
* @param w width of the collider
|
|
390
|
+
* @param h height of the collider
|
|
391
|
+
*/
|
|
392
|
+
addSensor(offsetX: number, offsetY: number, w?: number, h?: number): void;
|
|
393
|
+
/**
|
|
394
|
+
* The mass of the sprite's physics body.
|
|
395
|
+
*/
|
|
396
|
+
get mass(): number;
|
|
397
|
+
set mass(val: number);
|
|
398
|
+
/**
|
|
399
|
+
* The center of mass of the sprite's physics body, the point at which
|
|
400
|
+
* the physics body is balanced and rotates around. By default it's the
|
|
401
|
+
* same as the sprite's position, but it can be changed with this setter.
|
|
402
|
+
*/
|
|
403
|
+
get centerOfMass(): { x: number; y: number };
|
|
404
|
+
set centerOfMass(val: { x: number; y: number });
|
|
405
|
+
/**
|
|
406
|
+
* If true, the center of mass of the sprite's physics body is fixed to
|
|
407
|
+
* the sprite's [x, y] position.
|
|
408
|
+
*
|
|
409
|
+
* It prevents the center of mass from being recalculated (moved) when adding or
|
|
410
|
+
* removing colliders or sensors. Set it to false to allow dynamic center of mass
|
|
411
|
+
* recalculation.
|
|
412
|
+
* @default true
|
|
413
|
+
*/
|
|
414
|
+
get fixedCenterOfMass(): boolean;
|
|
415
|
+
set fixedCenterOfMass(val: boolean);
|
|
416
|
+
/**
|
|
417
|
+
* Recalculates the sprite's mass based on its current
|
|
418
|
+
* density and size.
|
|
419
|
+
*/
|
|
420
|
+
resetMass(): void;
|
|
421
|
+
/**
|
|
422
|
+
* The angle of the sprite's rotation, not the direction it's moving.
|
|
423
|
+
*
|
|
424
|
+
* If angleMode is set to "degrees", the value will be returned in
|
|
425
|
+
* a range of -180 to 180.
|
|
426
|
+
* @default 0
|
|
427
|
+
*/
|
|
428
|
+
get rotation(): number;
|
|
429
|
+
set rotation(val: number);
|
|
430
|
+
/**
|
|
431
|
+
* Removes colliders from the sprite's physics body.
|
|
432
|
+
*/
|
|
433
|
+
removeColliders(): void;
|
|
434
|
+
/**
|
|
435
|
+
* Removes overlap sensors from the sprite's physics body.
|
|
436
|
+
*/
|
|
437
|
+
removeSensors(): void;
|
|
438
|
+
/**
|
|
439
|
+
* If true, a sprite is updated by q5play before each physics update.
|
|
440
|
+
* @default true
|
|
441
|
+
*/
|
|
442
|
+
get autoUpdate(): boolean;
|
|
443
|
+
set autoUpdate(val: boolean);
|
|
444
|
+
/**
|
|
445
|
+
* If true, a sprite is drawn by q5play after each physics update.
|
|
446
|
+
* @default true
|
|
447
|
+
*/
|
|
448
|
+
get autoDraw(): boolean;
|
|
449
|
+
set autoDraw(val: boolean);
|
|
450
|
+
/**
|
|
451
|
+
* Controls the ability for a sprite to "sleep".
|
|
452
|
+
*
|
|
453
|
+
* "Sleeping" sprites are not included in the physics simulation, a
|
|
454
|
+
* sprite starts "sleeping" when it stops moving and doesn't collide
|
|
455
|
+
* with anything that it wasn't already colliding with.
|
|
456
|
+
* @default true
|
|
457
|
+
*/
|
|
458
|
+
get allowSleeping(): boolean;
|
|
459
|
+
set allowSleeping(val: boolean);
|
|
460
|
+
/**
|
|
461
|
+
* The bounciness of the sprite's physics body.
|
|
462
|
+
* @default 0.2
|
|
463
|
+
*/
|
|
464
|
+
get bounciness(): number;
|
|
465
|
+
set bounciness(val: number);
|
|
466
|
+
/**
|
|
467
|
+
* The speed of the sprite's rotation in angles per frame.
|
|
468
|
+
* @default 0
|
|
469
|
+
*/
|
|
470
|
+
get rotationSpeed(): number;
|
|
471
|
+
set rotationSpeed(val: number);
|
|
472
|
+
/**
|
|
473
|
+
* The sprite's current fill color.
|
|
474
|
+
*
|
|
475
|
+
* By default sprites get a random color.
|
|
476
|
+
*/
|
|
477
|
+
get color(): Q5.Color;
|
|
478
|
+
set color(val: Q5.Color);
|
|
479
|
+
/**
|
|
480
|
+
* The sprite's current fill colour.
|
|
481
|
+
*
|
|
482
|
+
* By default sprites get a random color.
|
|
483
|
+
*/
|
|
484
|
+
get colour(): Q5.Color;
|
|
485
|
+
set colour(val: Q5.Color);
|
|
486
|
+
/**
|
|
487
|
+
* The sprite's current fill color.
|
|
488
|
+
*
|
|
489
|
+
* By default sprites get a random color.
|
|
490
|
+
*/
|
|
491
|
+
get fill(): Q5.Color;
|
|
492
|
+
set fill(val: Q5.Color);
|
|
493
|
+
/**
|
|
494
|
+
* The sprite's stroke color.
|
|
495
|
+
*/
|
|
496
|
+
get stroke(): Q5.Color;
|
|
497
|
+
set stroke(val: Q5.Color);
|
|
498
|
+
/**
|
|
499
|
+
* The sprite's stroke weight, the thickness of its outline.
|
|
500
|
+
*/
|
|
501
|
+
get strokeWeight(): number;
|
|
502
|
+
set strokeWeight(val: number);
|
|
503
|
+
/**
|
|
504
|
+
* The sprite's text fill color. Black by default.
|
|
505
|
+
* @default black (#000000)
|
|
506
|
+
*/
|
|
507
|
+
get textFill(): Q5.Color;
|
|
508
|
+
set textFill(val: Q5.Color);
|
|
509
|
+
/**
|
|
510
|
+
* The sprite's text size, the sketch's current textSize by default.
|
|
511
|
+
*/
|
|
512
|
+
get textSize(): number;
|
|
513
|
+
set textSize(val: number);
|
|
514
|
+
/**
|
|
515
|
+
* The sprite's text stroke color.
|
|
516
|
+
* No stroke by default, does not inherit from the sketch's stroke color.
|
|
517
|
+
* @default undefined
|
|
518
|
+
*/
|
|
519
|
+
get textStroke(): Q5.Color;
|
|
520
|
+
set textStroke(val: Q5.Color);
|
|
521
|
+
/**
|
|
522
|
+
* The sprite's text stroke weight, the thickness of its outline.
|
|
523
|
+
* No stroke by default, does not inherit from the sketch's stroke weight.
|
|
524
|
+
* @default undefined
|
|
525
|
+
*/
|
|
526
|
+
get textStrokeWeight(): number;
|
|
527
|
+
set textStrokeWeight(val: number);
|
|
528
|
+
/**
|
|
529
|
+
* The tile character that represents the sprite in a tile map.
|
|
530
|
+
*/
|
|
531
|
+
get tile(): string;
|
|
532
|
+
set tile(val: string);
|
|
533
|
+
/**
|
|
534
|
+
* A bearing indicates the direction that needs to be followed to
|
|
535
|
+
* reach a destination.
|
|
536
|
+
*
|
|
537
|
+
* Setting a sprite's bearing doesn't do anything by itself.
|
|
538
|
+
* You can apply a force to the sprite at its bearing angle
|
|
539
|
+
* using the `applyForce` function.
|
|
540
|
+
*/
|
|
541
|
+
get bearing(): number;
|
|
542
|
+
set bearing(val: number);
|
|
543
|
+
/**
|
|
544
|
+
* If true, outlines of the sprite's colliders and sensors will be drawn.
|
|
545
|
+
* @default false
|
|
546
|
+
*/
|
|
547
|
+
get debug(): boolean;
|
|
548
|
+
set debug(val: boolean);
|
|
549
|
+
/**
|
|
550
|
+
* The density of the sprite's physics body.
|
|
551
|
+
* @default 1
|
|
552
|
+
*/
|
|
553
|
+
get density(): number;
|
|
554
|
+
set density(val: number);
|
|
555
|
+
/**
|
|
556
|
+
* The angle of the sprite's movement.
|
|
557
|
+
* @default 0 ("right")
|
|
558
|
+
*/
|
|
559
|
+
get direction(): number;
|
|
560
|
+
set direction(val: number);
|
|
561
|
+
/**
|
|
562
|
+
* The amount of resistance a sprite has to being moved.
|
|
563
|
+
* @default 0
|
|
564
|
+
*/
|
|
565
|
+
get drag(): number;
|
|
566
|
+
set drag(val: number);
|
|
567
|
+
/**
|
|
568
|
+
* Displays the sprite.
|
|
569
|
+
*
|
|
570
|
+
* This function is called automatically at the end of each
|
|
571
|
+
* sketch `draw` function call but it can also be run
|
|
572
|
+
* by users to customize the order sprites are drawn in relation
|
|
573
|
+
* to other stuff drawn on the canvas. Also see the sprite.layer
|
|
574
|
+
* property.
|
|
575
|
+
*
|
|
576
|
+
* A sprite's draw function can be overridden with a
|
|
577
|
+
* custom draw function, inside this function (0, 0) is the center of
|
|
578
|
+
* the sprite.
|
|
579
|
+
*/
|
|
580
|
+
get draw(): Function;
|
|
581
|
+
set draw(val: Function);
|
|
582
|
+
/**
|
|
583
|
+
* The amount the sprite's colliders resist moving
|
|
584
|
+
* when rubbing against other colliders.
|
|
585
|
+
* @default 0.5
|
|
586
|
+
*/
|
|
587
|
+
get friction(): number;
|
|
588
|
+
set friction(val: number);
|
|
589
|
+
/**
|
|
590
|
+
* The sprite's heading. This is a string that can be set to
|
|
591
|
+
* "up", "down", "left", "right", "upRight", "upLeft", "downRight"
|
|
592
|
+
*
|
|
593
|
+
* The setter's input parser ignores capitalization, spaces,
|
|
594
|
+
* underscores, dashes, and cardinal direction word order.
|
|
595
|
+
* @default undefined
|
|
596
|
+
*/
|
|
597
|
+
get heading(): string;
|
|
598
|
+
set heading(val: string);
|
|
599
|
+
/**
|
|
600
|
+
* True if the sprite is moving.
|
|
601
|
+
* @readonly
|
|
602
|
+
*/
|
|
603
|
+
get isMoving(): boolean;
|
|
604
|
+
/**
|
|
605
|
+
* Set this to true if the sprite goes really fast to prevent
|
|
606
|
+
* inaccurate physics simulation.
|
|
607
|
+
* @default false
|
|
608
|
+
*/
|
|
609
|
+
get isSuperFast(): boolean;
|
|
610
|
+
set isSuperFast(val: boolean);
|
|
611
|
+
/**
|
|
612
|
+
* Sprites with the highest layer value get drawn first.
|
|
613
|
+
*
|
|
614
|
+
* By default sprites are drawn in the order they were created in.
|
|
615
|
+
*/
|
|
616
|
+
get layer(): number;
|
|
617
|
+
set layer(val: number);
|
|
618
|
+
/**
|
|
619
|
+
* When the physics simulation is progressed in `world.physicsUpdate`,
|
|
620
|
+
* each sprite's life is decreased by `world.timeScale`.
|
|
621
|
+
*
|
|
622
|
+
* If life becomes less than or equal to 0, the sprite will
|
|
623
|
+
* be removed.
|
|
624
|
+
* @default Infinity
|
|
625
|
+
*/
|
|
626
|
+
get life(): number;
|
|
627
|
+
set life(val: number);
|
|
628
|
+
/**
|
|
629
|
+
* The sprite's opacity. 0 is transparent, 1 is opaque.
|
|
630
|
+
* @default 1
|
|
631
|
+
*/
|
|
632
|
+
get opacity(): number;
|
|
633
|
+
set opacity(val: number);
|
|
634
|
+
/**
|
|
635
|
+
* Alias for sprite.prevPos
|
|
636
|
+
*/
|
|
637
|
+
get previousPosition(): any;
|
|
638
|
+
set previousPosition(val: any);
|
|
639
|
+
/**
|
|
640
|
+
* Alias for sprite.prevRotation
|
|
641
|
+
*/
|
|
642
|
+
get previousRotation(): number;
|
|
643
|
+
set previousRotation(val: number);
|
|
644
|
+
/**
|
|
645
|
+
* If true, q5play will draw sprites at integer pixel precision.
|
|
646
|
+
*
|
|
647
|
+
* This is useful for making retro games.
|
|
648
|
+
*
|
|
649
|
+
* By default q5play draws sprites with subpixel rendering.
|
|
650
|
+
* @default false
|
|
651
|
+
*/
|
|
652
|
+
get pixelPerfect(): boolean;
|
|
653
|
+
set pixelPerfect(val: boolean);
|
|
654
|
+
/**
|
|
655
|
+
* If the sprite has been removed from the world.
|
|
656
|
+
* @default false
|
|
657
|
+
*/
|
|
658
|
+
get removed(): boolean;
|
|
659
|
+
set removed(val: boolean);
|
|
660
|
+
/**
|
|
661
|
+
* Simulates friction that slows down a sprite rolling on another sprite,
|
|
662
|
+
* like a soccer ball rolling to a stop on high grass.
|
|
663
|
+
* @default 0
|
|
664
|
+
*/
|
|
665
|
+
get rollingResistance(): number;
|
|
666
|
+
set rollingResistance(val: number);
|
|
667
|
+
/**
|
|
668
|
+
* The amount the sprite resists rotating.
|
|
669
|
+
* @default 0
|
|
670
|
+
*/
|
|
671
|
+
get rotationDrag(): number;
|
|
672
|
+
set rotationDrag(val: number);
|
|
673
|
+
/**
|
|
674
|
+
* Known issue, this doesn't work yet.
|
|
675
|
+
* https://github.com/q5play/q5play/issues/36
|
|
676
|
+
*
|
|
677
|
+
* If true, the sprite can not rotate.
|
|
678
|
+
* @deprecated
|
|
679
|
+
* @default false
|
|
680
|
+
*/
|
|
681
|
+
get rotationLock(): boolean;
|
|
682
|
+
set rotationLock(val: boolean);
|
|
683
|
+
/**
|
|
684
|
+
* Horizontal and vertical scale of the sprite.
|
|
685
|
+
*
|
|
686
|
+
* Components can be negative to flip/mirror the sprite on an axis.
|
|
687
|
+
*
|
|
688
|
+
* The `valueOf` function for `sprite.scale` returns the scale as a
|
|
689
|
+
* number. This enables users to do things like `sprite.scale *= 2`
|
|
690
|
+
* to double the sprite's scale.
|
|
691
|
+
* @default {x: 1, y: 1}
|
|
692
|
+
*/
|
|
693
|
+
get scale(): number | { x: number; y: number };
|
|
694
|
+
set scale(val: number | [] | { x: number; y: number });
|
|
695
|
+
/**
|
|
696
|
+
* Scales the the sprite.
|
|
697
|
+
* @param x scaleX or uniform scale factor
|
|
698
|
+
* @param y scaleY
|
|
699
|
+
*/
|
|
700
|
+
scaleBy(x: number, y?: number): void;
|
|
701
|
+
/**
|
|
702
|
+
* Wake a sprite up or put it to sleep.
|
|
703
|
+
*
|
|
704
|
+
* "Sleeping" sprites are not included in the physics simulation, a
|
|
705
|
+
* sprite starts "sleeping" when it stops moving and doesn't collide
|
|
706
|
+
* with anything that it wasn't already colliding with.
|
|
707
|
+
* @default true
|
|
708
|
+
*/
|
|
709
|
+
get sleeping(): boolean;
|
|
710
|
+
set sleeping(val: boolean);
|
|
711
|
+
/**
|
|
712
|
+
* The sprite's speed.
|
|
713
|
+
*
|
|
714
|
+
* Setting speed to a negative value will make the sprite move
|
|
715
|
+
* 180 degrees opposite of its current direction angle.
|
|
716
|
+
* @default 0
|
|
717
|
+
*/
|
|
718
|
+
get speed(): number;
|
|
719
|
+
set speed(val: number);
|
|
720
|
+
/**
|
|
721
|
+
* Efficiently sets the sprite's speed and direction at the same time.
|
|
722
|
+
* @param speed
|
|
723
|
+
* @param direction
|
|
724
|
+
*/
|
|
725
|
+
setSpeedAndDirection(speed: number, direction: number): void;
|
|
726
|
+
/**
|
|
727
|
+
* The sprite's speed along the surface of its collider(s),
|
|
728
|
+
* like a conveyor belt.
|
|
729
|
+
* @default 0
|
|
730
|
+
*/
|
|
731
|
+
get surfaceSpeed(): number;
|
|
732
|
+
set surfaceSpeed(val: number);
|
|
733
|
+
/**
|
|
734
|
+
* Tint color applied to the sprite when drawn.
|
|
735
|
+
*
|
|
736
|
+
* Note that this is not good for performance, you should probably
|
|
737
|
+
* pre-render the effect if you want to use it a lot.
|
|
738
|
+
* @default undefined
|
|
739
|
+
*/
|
|
740
|
+
get tint(): Q5.Color;
|
|
741
|
+
set tint(val: Q5.Color);
|
|
742
|
+
/**
|
|
743
|
+
* If true the sprite is shown, if set to false the sprite is hidden.
|
|
744
|
+
*
|
|
745
|
+
* Becomes null when the sprite is off screen but will be drawn and
|
|
746
|
+
* set to true again if it goes back on screen.
|
|
747
|
+
* @default true
|
|
748
|
+
*/
|
|
749
|
+
get visible(): boolean;
|
|
750
|
+
set visible(val: boolean);
|
|
751
|
+
/**
|
|
752
|
+
* The position vector {x, y}
|
|
753
|
+
*/
|
|
754
|
+
get pos(): Q5.Vector;
|
|
755
|
+
set pos(val: [] | { x: number; y: number } | Q5.Vector);
|
|
756
|
+
/**
|
|
757
|
+
* The position vector {x, y}
|
|
758
|
+
*/
|
|
759
|
+
get position(): Q5.Vector;
|
|
760
|
+
set position(val: [] | { x: number; y: number } | Q5.Vector);
|
|
761
|
+
/**
|
|
762
|
+
* The sprite's absolute position on the canvas.
|
|
763
|
+
* @readonly
|
|
764
|
+
*/
|
|
765
|
+
get canvasPos(): any;
|
|
766
|
+
/**
|
|
767
|
+
* Half the width of the sprite.
|
|
768
|
+
*/
|
|
769
|
+
get hw(): number;
|
|
770
|
+
set hw(val: number);
|
|
771
|
+
/**
|
|
772
|
+
* The width of the sprite.
|
|
773
|
+
*/
|
|
774
|
+
get width(): number;
|
|
775
|
+
set width(val: number);
|
|
776
|
+
/**
|
|
777
|
+
* Half the width of the sprite.
|
|
778
|
+
*/
|
|
779
|
+
get halfWidth(): number;
|
|
780
|
+
set halfWidth(val: number);
|
|
781
|
+
/**
|
|
782
|
+
* Half the height of the sprite.
|
|
783
|
+
*/
|
|
784
|
+
get hh(): number;
|
|
785
|
+
set hh(val: number);
|
|
786
|
+
/**
|
|
787
|
+
* The height of the sprite.
|
|
788
|
+
*/
|
|
789
|
+
get height(): number;
|
|
790
|
+
set height(val: number);
|
|
791
|
+
/**
|
|
792
|
+
* Half the height of the sprite.
|
|
793
|
+
*/
|
|
794
|
+
get halfHeight(): number;
|
|
795
|
+
set halfHeight(val: number);
|
|
796
|
+
/**
|
|
797
|
+
* The diameter of a circular sprite.
|
|
798
|
+
*/
|
|
799
|
+
get d(): number;
|
|
800
|
+
set d(val: number);
|
|
801
|
+
/**
|
|
802
|
+
* The diameter of a circular sprite.
|
|
803
|
+
*/
|
|
804
|
+
get diameter(): number;
|
|
805
|
+
set diameter(val: number);
|
|
806
|
+
/**
|
|
807
|
+
* The radius of a circular sprite.
|
|
808
|
+
*/
|
|
809
|
+
get r(): number;
|
|
810
|
+
set r(val: number);
|
|
811
|
+
/**
|
|
812
|
+
* The radius of a circular sprite.
|
|
813
|
+
*/
|
|
814
|
+
get radius(): number;
|
|
815
|
+
set radius(val: number);
|
|
816
|
+
/**
|
|
817
|
+
* Runs before each physics update by default.
|
|
818
|
+
*
|
|
819
|
+
* Set this to a custom function that handles input, directs sprite movement,
|
|
820
|
+
* and performs other tasks that should run before the physics update.
|
|
821
|
+
*
|
|
822
|
+
* Optionally, users can run this function manually in q5play's `update`
|
|
823
|
+
* function.
|
|
824
|
+
*/
|
|
825
|
+
get update(): Function;
|
|
826
|
+
set update(val: Function);
|
|
827
|
+
/**
|
|
828
|
+
* The sprite's velocity vector {x, y}
|
|
829
|
+
* @default {x: 0, y: 0}
|
|
830
|
+
*/
|
|
831
|
+
get vel(): Q5.Vector;
|
|
832
|
+
set vel(val: [] | { x: number; y: number } | Q5.Vector);
|
|
833
|
+
/**
|
|
834
|
+
* The sprite's velocity vector {x, y}
|
|
835
|
+
* @default {x: 0, y: 0}
|
|
836
|
+
*/
|
|
837
|
+
get velocity(): Q5.Vector;
|
|
838
|
+
set velocity(val: [] | { x: number; y: number } | Q5.Vector);
|
|
839
|
+
/**
|
|
840
|
+
* Whether the sprite can be grabbed by a pointer.
|
|
841
|
+
*/
|
|
842
|
+
get grabbable(): boolean;
|
|
843
|
+
set grabbable(val: boolean);
|
|
844
|
+
/**
|
|
845
|
+
* A ratio that defines how much the sprite is affected by gravity.
|
|
846
|
+
* @default 1
|
|
847
|
+
*/
|
|
848
|
+
get gravityScale(): number;
|
|
849
|
+
set gravityScale(val: number);
|
|
850
|
+
/**
|
|
851
|
+
* If this function is given a force amount, the force is applied
|
|
852
|
+
* at the angle of the sprite's current bearing. Force can
|
|
853
|
+
* also be given as a vector.
|
|
854
|
+
*
|
|
855
|
+
* @param amount
|
|
856
|
+
* @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.
|
|
857
|
+
*/
|
|
858
|
+
applyForce(amount: number, origin?: any): void;
|
|
859
|
+
/**
|
|
860
|
+
* Applies a force that's scaled to the sprite's mass.
|
|
861
|
+
*
|
|
862
|
+
* @param amount
|
|
863
|
+
* @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.
|
|
864
|
+
*/
|
|
865
|
+
applyForceScaled(amount: number, origin?: any): void;
|
|
866
|
+
/**
|
|
867
|
+
* Applies a force to the sprite's center of mass attracting it to
|
|
868
|
+
* the given position.
|
|
869
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
870
|
+
* @param y
|
|
871
|
+
* @param force
|
|
872
|
+
*/
|
|
873
|
+
attractTo(x: number | any, y?: number, force?: number): void;
|
|
874
|
+
/**
|
|
875
|
+
* Applies a force to the sprite's center of mass repelling it to
|
|
876
|
+
* the given position.
|
|
877
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
878
|
+
* @param y
|
|
879
|
+
* @param force
|
|
880
|
+
*/
|
|
881
|
+
repelFrom(x: number | any, y?: number, force?: number): void;
|
|
882
|
+
/**
|
|
883
|
+
* Apply a torque on the sprite's physics body.
|
|
884
|
+
* Torque is the force that causes rotation.
|
|
885
|
+
* A positive torque will rotate the sprite clockwise.
|
|
886
|
+
* A negative torque will rotate the sprite counter-clockwise.
|
|
887
|
+
*
|
|
888
|
+
* This function is the rotational equivalent of applyForce().
|
|
889
|
+
* It will not imperatively set the sprite's rotation.
|
|
890
|
+
*
|
|
891
|
+
* @param torque
|
|
892
|
+
*/
|
|
893
|
+
applyTorque(torque: any): void;
|
|
894
|
+
/**
|
|
895
|
+
* Moves a sprite towards a position at a percentage of the distance
|
|
896
|
+
* between itself and the destination.
|
|
897
|
+
*
|
|
898
|
+
* @param x destination x or coordinate array or an object with x and y properties
|
|
899
|
+
* @param y destination y
|
|
900
|
+
* @param tracking percent of the distance to move towards the destination as a 0-1 value, default is 0.1 (10% tracking)
|
|
901
|
+
*/
|
|
902
|
+
moveTowards(x: number | any, y?: number, tracking?: number): void;
|
|
903
|
+
/**
|
|
904
|
+
* Moves the sprite away from a position, the opposite of moveTowards,
|
|
905
|
+
* at a percentage of the distance between itself and the position.
|
|
906
|
+
* @param x destination x or coordinate array or an object with x and y properties
|
|
907
|
+
* @param y destination y
|
|
908
|
+
* @param repel percent of the distance to the repel position as a 0-1 value, default is 0.1 (10% repel)
|
|
909
|
+
*/
|
|
910
|
+
moveAway(x: number | any, y?: number, repel?: number): void;
|
|
911
|
+
/**
|
|
912
|
+
* Rotates the sprite towards an angle or position
|
|
913
|
+
* with x and y properties.
|
|
914
|
+
*
|
|
915
|
+
* @param angle angle in degrees or coordinate array or an object with x and y properties
|
|
916
|
+
* @param tracking percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%)
|
|
917
|
+
* @param facing (only specify if position is given) rotation angle the sprite should be at when "facing" the position, default is 0
|
|
918
|
+
*/
|
|
919
|
+
rotateTowards(angle: number | any, tracking?: number): void;
|
|
920
|
+
/**
|
|
921
|
+
* Finds the angle from this sprite to the given position.
|
|
922
|
+
*
|
|
923
|
+
* Can be used to change the direction of a sprite so it moves
|
|
924
|
+
* to a position or object, as shown in the example.
|
|
925
|
+
*
|
|
926
|
+
* Used internally by `moveTo` and `moveTowards`.
|
|
927
|
+
*
|
|
928
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
929
|
+
* @param y
|
|
930
|
+
* @returns angle
|
|
931
|
+
*/
|
|
932
|
+
angleTo(x: number | any, y?: number): number;
|
|
933
|
+
/**
|
|
934
|
+
* Finds the rotation angle the sprite should be at when "facing"
|
|
935
|
+
* a position.
|
|
936
|
+
*
|
|
937
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
938
|
+
* @param y
|
|
939
|
+
* @param facing relative angle the sprite should be at when "facing" the position, default is 0
|
|
940
|
+
* @returns the rotation angle the sprite should be at when "facing" the position
|
|
941
|
+
*/
|
|
942
|
+
rotationToFace(x: number | any, y?: number, facing?: number): number;
|
|
943
|
+
/**
|
|
944
|
+
* Finds the minimum angle distance that the sprite would have
|
|
945
|
+
* to rotate to "face" a position at a specified facing rotation,
|
|
946
|
+
* taking into account the current rotation of the sprite.
|
|
947
|
+
*
|
|
948
|
+
* Used internally by `rotateTowards`.
|
|
949
|
+
*
|
|
950
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
951
|
+
* @param y
|
|
952
|
+
* @param facing relative angle the sprite should be at when "facing" the position, default is 0
|
|
953
|
+
* @returns the minimum angle distance to face the position
|
|
954
|
+
*/
|
|
955
|
+
angleToFace(x: number | any, y?: number, facing?: number): number;
|
|
956
|
+
/**
|
|
957
|
+
* Deletes the Sprite from the sketch and all the groups it
|
|
958
|
+
* belongs to.
|
|
959
|
+
*
|
|
960
|
+
* When a sprite is deleted it will not be drawn or updated anymore.
|
|
961
|
+
* If it has a physics body, it will be deleted from the physics simulation.
|
|
962
|
+
*
|
|
963
|
+
* There's no way to undo this operation. If you want to hide a
|
|
964
|
+
* sprite use `sprite.visible = false` instead.
|
|
965
|
+
*/
|
|
966
|
+
delete(): void;
|
|
967
|
+
/**
|
|
968
|
+
* Returns the sprite's unique identifier `sprite.idNum`.
|
|
969
|
+
* @returns the sprite's id
|
|
970
|
+
*/
|
|
971
|
+
toString(): string;
|
|
972
|
+
/**
|
|
973
|
+
* Returns true on the first frame that the sprite collides with the
|
|
974
|
+
* target sprite or group.
|
|
975
|
+
*
|
|
976
|
+
* Custom collision event handling can be done by using this function
|
|
977
|
+
* in an if statement or adding a callback as the second parameter.
|
|
978
|
+
*
|
|
979
|
+
* @param target
|
|
980
|
+
* @param callback
|
|
981
|
+
*/
|
|
982
|
+
collides(target: Sprite | Group, callback?: Function): boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Returns a truthy value while the sprite is colliding with the
|
|
985
|
+
* target sprite or group. The value is the number of frames that
|
|
986
|
+
* the sprite has been colliding with the target.
|
|
987
|
+
*
|
|
988
|
+
* @param target
|
|
989
|
+
* @param callback
|
|
990
|
+
* @return {Number} frames
|
|
991
|
+
*/
|
|
992
|
+
colliding(target: Sprite | Group, callback?: Function): number;
|
|
993
|
+
/**
|
|
994
|
+
* Returns true on the first frame that the sprite no longer overlaps
|
|
995
|
+
* with the target sprite or group.
|
|
996
|
+
*
|
|
997
|
+
* @param target
|
|
998
|
+
* @param callback
|
|
999
|
+
* @return {Boolean}
|
|
1000
|
+
*/
|
|
1001
|
+
collided(target: Sprite | Group, callback?: Function): boolean;
|
|
1002
|
+
/**
|
|
1003
|
+
* Returns true on the first frame that the sprite overlaps with the
|
|
1004
|
+
* target sprite or group.
|
|
1005
|
+
*
|
|
1006
|
+
* Custom overlap event handling can be done by using this function
|
|
1007
|
+
* in an if statement or adding a callback as the second parameter.
|
|
1008
|
+
*
|
|
1009
|
+
* @param target
|
|
1010
|
+
* @param callback
|
|
1011
|
+
*/
|
|
1012
|
+
overlaps(target: Sprite | Group, callback?: Function): boolean;
|
|
1013
|
+
/**
|
|
1014
|
+
* Returns a truthy value while the sprite is overlapping with the
|
|
1015
|
+
* target sprite or group. The value returned is the number of
|
|
1016
|
+
* frames the sprite has been overlapping with the target.
|
|
1017
|
+
*
|
|
1018
|
+
* @param target
|
|
1019
|
+
* @param callback
|
|
1020
|
+
* @return {Number} frames
|
|
1021
|
+
*/
|
|
1022
|
+
overlapping(target: Sprite | Group, callback?: Function): number;
|
|
1023
|
+
/**
|
|
1024
|
+
* Returns true on the first frame that the sprite no longer overlaps
|
|
1025
|
+
* with the target sprite or group.
|
|
1026
|
+
*
|
|
1027
|
+
* @param target
|
|
1028
|
+
* @param callback
|
|
1029
|
+
* @return {Boolean}
|
|
1030
|
+
*/
|
|
1031
|
+
overlapped(target: Sprite | Group, callback?: Function): boolean;
|
|
1032
|
+
/**
|
|
1033
|
+
* Sets a pass through contact relationship between the sprite
|
|
1034
|
+
* and a target sprite or group.
|
|
1035
|
+
* @param target
|
|
1036
|
+
*/
|
|
1037
|
+
pass(target: Sprite | Group): void;
|
|
1038
|
+
/**
|
|
1039
|
+
* Sets a pass through contact relationship between the sprite
|
|
1040
|
+
* and a target sprite or group.
|
|
1041
|
+
* @param target
|
|
1042
|
+
*/
|
|
1043
|
+
passes(target: Sprite | Group): void;
|
|
1044
|
+
/**
|
|
1045
|
+
* Creates overlap sensors that are the same size as the sprite's
|
|
1046
|
+
* colliders. If you'd like to add more sensors to a sprite, use the
|
|
1047
|
+
* `addSensor` function.
|
|
1048
|
+
*
|
|
1049
|
+
* Used internally if a sprite overlap detection
|
|
1050
|
+
* function is called but the sprite has no overlap sensors.
|
|
1051
|
+
*/
|
|
1052
|
+
addDefaultSensors(): void;
|
|
1053
|
+
/**
|
|
1054
|
+
* Returns the distance to another sprite, the mouse, a touch,
|
|
1055
|
+
* or any other object with x and y properties. Uses p5's `dist`
|
|
1056
|
+
* function.
|
|
1057
|
+
* @param o coordinate array or object with x and y properties
|
|
1058
|
+
* @returns distance
|
|
1059
|
+
*/
|
|
1060
|
+
distanceTo(o: any): number;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
class Ani extends Array<Q5.Image> {
|
|
1064
|
+
/**
|
|
1065
|
+
* Ani objects are an array of images
|
|
1066
|
+
* that can be displayed by a Visual or Sprite.
|
|
1067
|
+
*
|
|
1068
|
+
* @param args the frames of the animation
|
|
1069
|
+
*/
|
|
1070
|
+
constructor(...args: Q5.Image[]);
|
|
1071
|
+
/**
|
|
1072
|
+
* The name of the animation
|
|
1073
|
+
*/
|
|
1074
|
+
name: string;
|
|
1075
|
+
targetFrame: number;
|
|
1076
|
+
/**
|
|
1077
|
+
* The distance from the sprite or visual's position
|
|
1078
|
+
* that the animation is drawn at.
|
|
1079
|
+
* @prop {Number} x horizontal offset
|
|
1080
|
+
* @prop {Number} y vertical offset
|
|
1081
|
+
*/
|
|
1082
|
+
offset: { x: number; y: number };
|
|
1083
|
+
/**
|
|
1084
|
+
* True if the animation is currently playing.
|
|
1085
|
+
* @default true
|
|
1086
|
+
*/
|
|
1087
|
+
playing: boolean;
|
|
1088
|
+
/**
|
|
1089
|
+
* Animation visibility.
|
|
1090
|
+
* @default true
|
|
1091
|
+
*/
|
|
1092
|
+
visible: boolean;
|
|
1093
|
+
/**
|
|
1094
|
+
* If set to false the animation will stop after reaching the last frame
|
|
1095
|
+
* @default true
|
|
1096
|
+
*/
|
|
1097
|
+
looping: boolean;
|
|
1098
|
+
/**
|
|
1099
|
+
* Ends the loop on frame 0 instead of the last frame.
|
|
1100
|
+
* This is useful for animations that are symmetric.
|
|
1101
|
+
* For example a walking cycle where the first frame is the
|
|
1102
|
+
* same as the last frame.
|
|
1103
|
+
* @default false
|
|
1104
|
+
*/
|
|
1105
|
+
endOnFirstFrame: boolean;
|
|
1106
|
+
/**
|
|
1107
|
+
* True if frame changed during the last draw cycle
|
|
1108
|
+
*/
|
|
1109
|
+
frameChanged: boolean;
|
|
1110
|
+
onComplete: any;
|
|
1111
|
+
onChange: any;
|
|
1112
|
+
rotation: any;
|
|
1113
|
+
spriteSheet: any;
|
|
1114
|
+
/**
|
|
1115
|
+
* The index of the current frame that the animation is on.
|
|
1116
|
+
*/
|
|
1117
|
+
get frame(): number;
|
|
1118
|
+
set frame(val: number);
|
|
1119
|
+
/**
|
|
1120
|
+
* Delay between frames in number of draw cycles.
|
|
1121
|
+
* If set to 4 the framerate of the animation would be the
|
|
1122
|
+
* sketch framerate divided by 4 (60fps = 15fps)
|
|
1123
|
+
* @default 4
|
|
1124
|
+
*/
|
|
1125
|
+
get frameDelay(): number;
|
|
1126
|
+
set frameDelay(val: number);
|
|
1127
|
+
/**
|
|
1128
|
+
* The animation's scale.
|
|
1129
|
+
*
|
|
1130
|
+
* Can be set to a number to scale both x and y
|
|
1131
|
+
* or an object with x and/or y properties.
|
|
1132
|
+
* @default 1
|
|
1133
|
+
*/
|
|
1134
|
+
get scale(): number | { x: number; y: number };
|
|
1135
|
+
set scale(val: number | { x: number; y: number });
|
|
1136
|
+
/**
|
|
1137
|
+
* Make a copy of the animation, with its own playback state,
|
|
1138
|
+
* independent of the original animation.
|
|
1139
|
+
* @return {Ani}
|
|
1140
|
+
*/
|
|
1141
|
+
clone(): Ani;
|
|
1142
|
+
/**
|
|
1143
|
+
* Updates the animation's playback state. This is called automatically
|
|
1144
|
+
*/
|
|
1145
|
+
update(): void;
|
|
1146
|
+
/**
|
|
1147
|
+
* Plays the animation, starting from the specified frame.
|
|
1148
|
+
*
|
|
1149
|
+
* @returns [Promise] a promise that resolves when the animation completes
|
|
1150
|
+
*/
|
|
1151
|
+
play(frame: any): Promise<any>;
|
|
1152
|
+
/**
|
|
1153
|
+
* Pauses the animation.
|
|
1154
|
+
*/
|
|
1155
|
+
pause(frame: any): void;
|
|
1156
|
+
/**
|
|
1157
|
+
* Stops the animation. Alt for pause.
|
|
1158
|
+
*/
|
|
1159
|
+
stop(frame: any): void;
|
|
1160
|
+
/**
|
|
1161
|
+
* Plays the animation backwards.
|
|
1162
|
+
* Equivalent to ani.goToFrame(0)
|
|
1163
|
+
*
|
|
1164
|
+
* @returns [Promise] a promise that resolves when the animation completes
|
|
1165
|
+
* rewinding
|
|
1166
|
+
*/
|
|
1167
|
+
rewind(): Promise<any>;
|
|
1168
|
+
/**
|
|
1169
|
+
* Plays the animation forwards and loops it.
|
|
1170
|
+
*/
|
|
1171
|
+
loop(): void;
|
|
1172
|
+
/**
|
|
1173
|
+
* Prevents the animation from looping
|
|
1174
|
+
*/
|
|
1175
|
+
noLoop(): void;
|
|
1176
|
+
/**
|
|
1177
|
+
* Goes to the next frame and stops.
|
|
1178
|
+
*/
|
|
1179
|
+
nextFrame(): void;
|
|
1180
|
+
/**
|
|
1181
|
+
* Goes to the previous frame and stops.
|
|
1182
|
+
*/
|
|
1183
|
+
previousFrame(): void;
|
|
1184
|
+
/**
|
|
1185
|
+
* Plays the animation forward or backward toward a target frame.
|
|
1186
|
+
*
|
|
1187
|
+
* @param toFrame Frame number destination (starts from 0)
|
|
1188
|
+
* @returns [Promise] a promise that resolves when the animation completes
|
|
1189
|
+
*/
|
|
1190
|
+
goToFrame(toFrame: number): Promise<any>;
|
|
1191
|
+
/**
|
|
1192
|
+
* The index of the last frame. Read only.
|
|
1193
|
+
*/
|
|
1194
|
+
get lastFrame(): number;
|
|
1195
|
+
/**
|
|
1196
|
+
* The current frame as Q5.Image. Read only.
|
|
1197
|
+
*/
|
|
1198
|
+
get frameImage(): Q5.Image;
|
|
1199
|
+
/**
|
|
1200
|
+
* Width of the animation's current frame.
|
|
1201
|
+
*/
|
|
1202
|
+
get w(): number;
|
|
1203
|
+
/**
|
|
1204
|
+
* Width of the animation's current frame.
|
|
1205
|
+
*/
|
|
1206
|
+
get width(): number;
|
|
1207
|
+
get defaultWidth(): any;
|
|
1208
|
+
/**
|
|
1209
|
+
* Height of the animation's current frame.
|
|
1210
|
+
*/
|
|
1211
|
+
get h(): number;
|
|
1212
|
+
/**
|
|
1213
|
+
* Height of the animation's current frame.
|
|
1214
|
+
*/
|
|
1215
|
+
get height(): number;
|
|
1216
|
+
get defaultHeight(): any;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Stores animations.
|
|
1220
|
+
*
|
|
1221
|
+
* Used internally to create `sprite.anis` and `group.anis`.
|
|
1222
|
+
*
|
|
1223
|
+
* In instances of this class, the keys are animation names,
|
|
1224
|
+
* values are Ani objects.
|
|
1225
|
+
*/
|
|
1226
|
+
class Anis {
|
|
1227
|
+
frameDelay: number;
|
|
1228
|
+
offset: { x: number; y: number };
|
|
1229
|
+
scale: number | { x: number; y: number };
|
|
1230
|
+
looping: boolean;
|
|
1231
|
+
playing: boolean;
|
|
1232
|
+
/**
|
|
1233
|
+
* Cuts sprite sheet frames into separate images, instead of rendering
|
|
1234
|
+
* sections of the sprite sheet.
|
|
1235
|
+
*
|
|
1236
|
+
* Avoids edge bleeding artifacts caused by rotation and scaling,
|
|
1237
|
+
* but uses more memory and may cause longer load times.
|
|
1238
|
+
*/
|
|
1239
|
+
cutFrames: boolean;
|
|
1240
|
+
endOnFirstFrame: boolean;
|
|
1241
|
+
w: number;
|
|
1242
|
+
width: number;
|
|
1243
|
+
h: number;
|
|
1244
|
+
height: number;
|
|
1245
|
+
/**
|
|
1246
|
+
* Frame size of the animations in the collection, in the format "WIDTHxHEIGHT", for example "32x32".
|
|
1247
|
+
*/
|
|
1248
|
+
frameSize: string;
|
|
1249
|
+
/**
|
|
1250
|
+
* The sprite sheet image used by the animations in the collection.
|
|
1251
|
+
*/
|
|
1252
|
+
spriteSheet: Q5.Image;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Visual objects store images and animations that can be displayed
|
|
1257
|
+
* with respect to the camera.
|
|
1258
|
+
*/
|
|
1259
|
+
class Visuals extends Array<Visual> {
|
|
1260
|
+
/**
|
|
1261
|
+
* Draws the visuals on the canvas.
|
|
1262
|
+
*/
|
|
1263
|
+
draw(): void;
|
|
1264
|
+
/**
|
|
1265
|
+
* Current image.
|
|
1266
|
+
*/
|
|
1267
|
+
img: Q5.Image;
|
|
1268
|
+
/**
|
|
1269
|
+
* Current animation.
|
|
1270
|
+
*/
|
|
1271
|
+
ani: Ani;
|
|
1272
|
+
/**
|
|
1273
|
+
* Stores animations.
|
|
1274
|
+
* Keys are the animation label, values are Ani objects
|
|
1275
|
+
*/
|
|
1276
|
+
get anis(): Anis;
|
|
1277
|
+
/**
|
|
1278
|
+
* Adds an animation to the Group or Visuals array.
|
|
1279
|
+
*
|
|
1280
|
+
* @param spriteSheetURL the URL of the sprite sheet image
|
|
1281
|
+
* @param frameCount the number of frames in the sprite sheet
|
|
1282
|
+
* @returns A promise that fulfills when the animation is loaded
|
|
1283
|
+
*/
|
|
1284
|
+
addAni(spriteSheetURL: string, frameCount: number): Promise<void>;
|
|
1285
|
+
/**
|
|
1286
|
+
* Add multiple animations to the Group or Visuals array.
|
|
1287
|
+
*
|
|
1288
|
+
* @param spriteSheetURL the URL of the sprite sheet image
|
|
1289
|
+
* @param frameSize the size of each frame in the sprite sheet in the format "WIDTHxHEIGHT" (example: "32x32")
|
|
1290
|
+
* @param atlases an object with animation names as keys and
|
|
1291
|
+
* an animation or animation atlas as values
|
|
1292
|
+
* @returns A promise that fulfills when the animations are loaded
|
|
1293
|
+
*/
|
|
1294
|
+
addAnis(spriteSheetURL: string, frameSize: string, atlases: {}): Promise<void>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Detects when visuals go outside the given culling boundary,
|
|
1297
|
+
* relative to the camera.
|
|
1298
|
+
* @param top top bound or boundary range
|
|
1299
|
+
* @param bottom bottom bound
|
|
1300
|
+
* @param left left bound
|
|
1301
|
+
* @param right right bound
|
|
1302
|
+
* @param cb the function to be run when a visual is culled,
|
|
1303
|
+
* it's given the visual being culled, if no callback is given then the visual's life is set to 0
|
|
1304
|
+
* @return {Number} the number of visuals culled
|
|
1305
|
+
*/
|
|
1306
|
+
cull(top?: number, bottom?: number, left?: number, right?: number, cb?: Function): number;
|
|
1307
|
+
/**
|
|
1308
|
+
* The tile character that represents the Visuals or Group in a tile map.
|
|
1309
|
+
*/
|
|
1310
|
+
tile: string;
|
|
1311
|
+
/**
|
|
1312
|
+
* Adds sprites to the group based on a tile map.
|
|
1313
|
+
*
|
|
1314
|
+
* @param tiles
|
|
1315
|
+
* @param x x coordinate of the top left corner of the tile map, default is -colWidth * longest row / 2
|
|
1316
|
+
* @param y y coordinate of the top left corner of the tile map, default is -rowHeight * number of rows / 2
|
|
1317
|
+
* @param colWidth column width including spacing, default is the width of the first tile
|
|
1318
|
+
* @param rowHeight row height including spacing, default is the height of the first tile
|
|
1319
|
+
*/
|
|
1320
|
+
addTiles(tiles: string | string[], x?: number, y?: number, colWidth?: number, rowHeight?: number): void;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
class Group extends Visuals {
|
|
1324
|
+
/**
|
|
1325
|
+
* An array of sprites with similar traits and behaviors.
|
|
1326
|
+
*
|
|
1327
|
+
* Group extends Array, so you can use them in for of loops. They
|
|
1328
|
+
* inherit all the functions and properties of standard arrays
|
|
1329
|
+
* such as `group.length` and functions like `group.includes()`.
|
|
1330
|
+
*
|
|
1331
|
+
* Changing a group setting changes it for all the sprites in the
|
|
1332
|
+
* group, similar to class inheritance. Groups can have subgroups,
|
|
1333
|
+
* creating a hierarchy of inheritance.
|
|
1334
|
+
*
|
|
1335
|
+
* @param sprites the sprites to add to the group
|
|
1336
|
+
*/
|
|
1337
|
+
constructor(...sprites: Sprite[]);
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Horizontal position of group sprites.
|
|
1341
|
+
*/
|
|
1342
|
+
x: number;
|
|
1343
|
+
/**
|
|
1344
|
+
* Vertical position of group sprites.
|
|
1345
|
+
*/
|
|
1346
|
+
y: number;
|
|
1347
|
+
/**
|
|
1348
|
+
* Velocity of group sprites.
|
|
1349
|
+
*/
|
|
1350
|
+
vel: number;
|
|
1351
|
+
/**
|
|
1352
|
+
* Velocity of group sprites.
|
|
1353
|
+
*/
|
|
1354
|
+
velocity: number;
|
|
1355
|
+
/**
|
|
1356
|
+
* The angle of the group sprites' rotation, not the direction it's moving.
|
|
1357
|
+
*
|
|
1358
|
+
* If angleMode is set to "degrees", the value will be returned in
|
|
1359
|
+
* a range of -180 to 180.
|
|
1360
|
+
*/
|
|
1361
|
+
rotation: number;
|
|
1362
|
+
/**
|
|
1363
|
+
* The speed of the group sprites' rotation in angles per frame.
|
|
1364
|
+
*/
|
|
1365
|
+
rotationSpeed: number;
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* If true, group sprites are drawn by q5play after each physics update.
|
|
1369
|
+
*/
|
|
1370
|
+
autoDraw: boolean;
|
|
1371
|
+
/**
|
|
1372
|
+
* Controls the ability for group sprites to "sleep".
|
|
1373
|
+
*
|
|
1374
|
+
* "Sleeping" sprites are not included in the physics simulation, a
|
|
1375
|
+
* sprite starts "sleeping" when it stops moving and doesn't collide
|
|
1376
|
+
* with anything that it wasn't already colliding with.
|
|
1377
|
+
*/
|
|
1378
|
+
allowSleeping: boolean;
|
|
1379
|
+
/**
|
|
1380
|
+
* If true, group sprites are updated by q5play before each physics update.
|
|
1381
|
+
*/
|
|
1382
|
+
autoUpdate: number;
|
|
1383
|
+
/**
|
|
1384
|
+
* A bearing indicates the direction that needs to be followed to
|
|
1385
|
+
* reach a destination.
|
|
1386
|
+
*
|
|
1387
|
+
* Setting a group sprites' bearing doesn't do anything by itself.
|
|
1388
|
+
* You can apply a force to the group sprites at its bearing angle
|
|
1389
|
+
* using the `applyForce` function.
|
|
1390
|
+
*/
|
|
1391
|
+
bearing: number;
|
|
1392
|
+
/**
|
|
1393
|
+
* The bounciness of the group sprites' physics body.
|
|
1394
|
+
*/
|
|
1395
|
+
bounciness: number;
|
|
1396
|
+
/**
|
|
1397
|
+
* The group sprites' current fill color.
|
|
1398
|
+
*
|
|
1399
|
+
* By default sprites get a random color.
|
|
1400
|
+
*/
|
|
1401
|
+
color: Q5.Color;
|
|
1402
|
+
/**
|
|
1403
|
+
* The diameter of a circular sprite.
|
|
1404
|
+
*/
|
|
1405
|
+
d: number;
|
|
1406
|
+
/**
|
|
1407
|
+
* The diameter of a circular sprite.
|
|
1408
|
+
*/
|
|
1409
|
+
diameter: number;
|
|
1410
|
+
/**
|
|
1411
|
+
* If true, outlines of the group sprites' colliders and sensors will be drawn.
|
|
1412
|
+
*
|
|
1413
|
+
* Use the keyboard shortcut Command+B to toggle `allSprites.debug`.
|
|
1414
|
+
*/
|
|
1415
|
+
debug: boolean;
|
|
1416
|
+
/**
|
|
1417
|
+
* The density of the group sprites' physics body.
|
|
1418
|
+
*/
|
|
1419
|
+
density: number;
|
|
1420
|
+
/**
|
|
1421
|
+
* The angle of the group sprites' movement.
|
|
1422
|
+
*/
|
|
1423
|
+
direction: number;
|
|
1424
|
+
/**
|
|
1425
|
+
* The amount of resistance group sprites has to being moved.
|
|
1426
|
+
*/
|
|
1427
|
+
drag: number;
|
|
1428
|
+
// fill is an Array method, don't redefine it
|
|
1429
|
+
/**
|
|
1430
|
+
* The amount the group sprites' colliders resist moving
|
|
1431
|
+
* when rubbing against other colliders.
|
|
1432
|
+
*/
|
|
1433
|
+
friction: number;
|
|
1434
|
+
/**
|
|
1435
|
+
* Whether the group sprites can be grabbed by a pointer.
|
|
1436
|
+
*/
|
|
1437
|
+
grabbable: boolean;
|
|
1438
|
+
/**
|
|
1439
|
+
* A ratio that defines how much the group sprites are affected by gravity.
|
|
1440
|
+
*/
|
|
1441
|
+
gravityScale: number;
|
|
1442
|
+
/**
|
|
1443
|
+
* The group sprites' heading. This is a string that can be set to
|
|
1444
|
+
* "up", "down", "left", "right", "upRight", "upLeft", "downRight"
|
|
1445
|
+
*
|
|
1446
|
+
* The setter's input parser ignores capitalization, spaces,
|
|
1447
|
+
* underscores, dashes, and cardinal direction word order.
|
|
1448
|
+
*/
|
|
1449
|
+
heading: string;
|
|
1450
|
+
/**
|
|
1451
|
+
* The height of the group sprites.
|
|
1452
|
+
*/
|
|
1453
|
+
h: number;
|
|
1454
|
+
/**
|
|
1455
|
+
* The height of the group sprites.
|
|
1456
|
+
*/
|
|
1457
|
+
height: number;
|
|
1458
|
+
/**
|
|
1459
|
+
* Set this to true if the group sprites goes really fast to prevent
|
|
1460
|
+
* inaccurate physics simulation.
|
|
1461
|
+
*/
|
|
1462
|
+
isSuperFast: boolean;
|
|
1463
|
+
/**
|
|
1464
|
+
* Sprites with the highest layer value get drawn first.
|
|
1465
|
+
*
|
|
1466
|
+
* By default sprites are drawn in the order they were created in.
|
|
1467
|
+
*/
|
|
1468
|
+
layer: number;
|
|
1469
|
+
/**
|
|
1470
|
+
* When the physics simulation is progressed in `world.physicsUpdate`,
|
|
1471
|
+
* each sprite's life is decreased by `world.timeScale`.
|
|
1472
|
+
*
|
|
1473
|
+
* If life becomes less than or equal to 0, the group sprites will
|
|
1474
|
+
* be removed.
|
|
1475
|
+
*/
|
|
1476
|
+
life: number;
|
|
1477
|
+
/**
|
|
1478
|
+
* The mass of the group sprites' physics body.
|
|
1479
|
+
*/
|
|
1480
|
+
mass: number;
|
|
1481
|
+
/**
|
|
1482
|
+
* The physics type of the group sprites, which determines how it interacts with
|
|
1483
|
+
* other sprites in the physics simulation.
|
|
1484
|
+
*
|
|
1485
|
+
* It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
|
|
1486
|
+
*/
|
|
1487
|
+
physics: string;
|
|
1488
|
+
/**
|
|
1489
|
+
* The physics type of the group sprites, which determines how it interacts with
|
|
1490
|
+
* other sprites in the physics simulation.
|
|
1491
|
+
*
|
|
1492
|
+
* It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.
|
|
1493
|
+
*/
|
|
1494
|
+
physicsType: string;
|
|
1495
|
+
/**
|
|
1496
|
+
* If true, the group sprites' physics body is included in the physics simulation.
|
|
1497
|
+
*/
|
|
1498
|
+
physicsEnabled: boolean;
|
|
1499
|
+
/**
|
|
1500
|
+
* If true, q5play will draw sprites at integer pixel precision.
|
|
1501
|
+
*
|
|
1502
|
+
* This is useful for making retro games.
|
|
1503
|
+
*
|
|
1504
|
+
* By default q5play draws sprites with subpixel rendering.
|
|
1505
|
+
*/
|
|
1506
|
+
pixelPerfect: boolean;
|
|
1507
|
+
/**
|
|
1508
|
+
* Simulates friction that slows down group sprites rolling on another sprite,
|
|
1509
|
+
* like a soccer ball rolling to a stop on high grass.
|
|
1510
|
+
*/
|
|
1511
|
+
rollingResistance: number;
|
|
1512
|
+
/**
|
|
1513
|
+
* The amount the group sprites resists rotating.
|
|
1514
|
+
*/
|
|
1515
|
+
rotationDrag: number;
|
|
1516
|
+
/**
|
|
1517
|
+
* Known issue, this doesn't work.
|
|
1518
|
+
*
|
|
1519
|
+
* If true, the group sprites can not rotate.
|
|
1520
|
+
* @deprecated
|
|
1521
|
+
*/
|
|
1522
|
+
rotationLock: boolean;
|
|
1523
|
+
/**
|
|
1524
|
+
* Horizontal and vertical scale of the group sprites.
|
|
1525
|
+
*
|
|
1526
|
+
* Components can be negative to flip/mirror the group sprites on an axis.
|
|
1527
|
+
*
|
|
1528
|
+
* The `valueOf` function for `sprite.scale` returns the scale as a
|
|
1529
|
+
* number. This enables users to do things like `sprite.scale *= 2`
|
|
1530
|
+
* to double the group sprites' scale.
|
|
1531
|
+
*/
|
|
1532
|
+
scale: number | Q5.Vector;
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Wake group sprites up or put it to sleep.
|
|
1536
|
+
*
|
|
1537
|
+
* "Sleeping" sprites are not included in the physics simulation, a
|
|
1538
|
+
* sprite starts "sleeping" when it stops moving and doesn't collide
|
|
1539
|
+
* with anything that it wasn't already colliding with.
|
|
1540
|
+
*/
|
|
1541
|
+
sleeping: boolean;
|
|
1542
|
+
/**
|
|
1543
|
+
* The group sprites' stroke color.
|
|
1544
|
+
*/
|
|
1545
|
+
stroke: Q5.Color;
|
|
1546
|
+
/**
|
|
1547
|
+
* The group sprites' stroke weight, the thickness of its outline.
|
|
1548
|
+
*/
|
|
1549
|
+
strokeWeight: number;
|
|
1550
|
+
/**
|
|
1551
|
+
* The group sprites' speed.
|
|
1552
|
+
*
|
|
1553
|
+
* Setting speed to a negative value will make the group sprites move
|
|
1554
|
+
* 180 degrees opposite of its current direction angle.
|
|
1555
|
+
*/
|
|
1556
|
+
speed: number;
|
|
1557
|
+
/**
|
|
1558
|
+
* The group sprites' speed along the surface of its collider(s),
|
|
1559
|
+
* like a conveyor belt.
|
|
1560
|
+
*/
|
|
1561
|
+
surfaceSpeed: number;
|
|
1562
|
+
/**
|
|
1563
|
+
* Text displayed at the center of the group sprites.
|
|
1564
|
+
*/
|
|
1565
|
+
text: number;
|
|
1566
|
+
/**
|
|
1567
|
+
* The group sprites' text fill color. Black by default.
|
|
1568
|
+
*/
|
|
1569
|
+
textFill: Q5.Color;
|
|
1570
|
+
/**
|
|
1571
|
+
* The group sprites' text stroke color.
|
|
1572
|
+
* No stroke by default, does not inherit from the sketch's stroke color.
|
|
1573
|
+
*/
|
|
1574
|
+
textStroke: Q5.Color;
|
|
1575
|
+
/**
|
|
1576
|
+
* The group sprites' text stroke weight, the thickness of its outline.
|
|
1577
|
+
* No stroke by default, does not inherit from the sketch's stroke weight.
|
|
1578
|
+
*/
|
|
1579
|
+
textStrokeWeight: number;
|
|
1580
|
+
/**
|
|
1581
|
+
* The group sprites' text size, the sketch's current textSize by default.
|
|
1582
|
+
*/
|
|
1583
|
+
textSize: number;
|
|
1584
|
+
/**
|
|
1585
|
+
* If true the group sprites are shown, if set to false the group sprites are hidden.
|
|
1586
|
+
*
|
|
1587
|
+
* Becomes null when the group sprites are off screen but will be drawn and
|
|
1588
|
+
* set to true again if it goes back on screen.
|
|
1589
|
+
*/
|
|
1590
|
+
visible: boolean;
|
|
1591
|
+
/**
|
|
1592
|
+
* The width of the group sprites.
|
|
1593
|
+
*/
|
|
1594
|
+
w: number;
|
|
1595
|
+
/**
|
|
1596
|
+
* The width of the group sprites.
|
|
1597
|
+
*/
|
|
1598
|
+
width: number;
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* Each group has a unique id number. Don't change it!
|
|
1602
|
+
* It's useful for debugging.
|
|
1603
|
+
*/
|
|
1604
|
+
idNum: number;
|
|
1605
|
+
/**
|
|
1606
|
+
* Groups can have subgroups, which inherit the properties
|
|
1607
|
+
* of their parent groups.
|
|
1608
|
+
* @default []
|
|
1609
|
+
*/
|
|
1610
|
+
subgroups: {
|
|
1611
|
+
[x: string]: any;
|
|
1612
|
+
}[];
|
|
1613
|
+
/**
|
|
1614
|
+
* The direct parent group that this group inherits properties from.
|
|
1615
|
+
*/
|
|
1616
|
+
parent: any;
|
|
1617
|
+
/**
|
|
1618
|
+
* Creates a new sprite with the traits of the group and adds it to the group.
|
|
1619
|
+
*/
|
|
1620
|
+
Sprite: typeof Sprite;
|
|
1621
|
+
/**
|
|
1622
|
+
* Creates a new subgroup that inherits the traits of the group.
|
|
1623
|
+
*/
|
|
1624
|
+
Group: typeof Group;
|
|
1625
|
+
/**
|
|
1626
|
+
* A property of the `allSprites` group only,
|
|
1627
|
+
* that controls whether sprites are automatically deleted
|
|
1628
|
+
* when they are 10,000 pixels away from the camera.
|
|
1629
|
+
*
|
|
1630
|
+
* It only needs to be set to false once and then it will
|
|
1631
|
+
* remain false for the rest of the sketch, unless changed.
|
|
1632
|
+
*/
|
|
1633
|
+
autoCull: boolean;
|
|
1634
|
+
/**
|
|
1635
|
+
* New group sprites will not have physics bodies (can't have colliders).
|
|
1636
|
+
*/
|
|
1637
|
+
visualOnly: boolean;
|
|
1638
|
+
/**
|
|
1639
|
+
* Alias for `group.push`.
|
|
1640
|
+
*
|
|
1641
|
+
* Adds a sprite to the end of the group.
|
|
1642
|
+
*/
|
|
1643
|
+
add: (...sprites: Sprite[]) => number;
|
|
1644
|
+
/**
|
|
1645
|
+
* Alias for `group.includes`.
|
|
1646
|
+
*
|
|
1647
|
+
* Check if a sprite is in the group.
|
|
1648
|
+
*/
|
|
1649
|
+
contains: (searchElement: Sprite, fromIndex?: number) => boolean;
|
|
1650
|
+
/**
|
|
1651
|
+
* Depending on the value that the amount property is set to, the group will
|
|
1652
|
+
* either add or delete sprites.
|
|
1653
|
+
*/
|
|
1654
|
+
get amount(): number;
|
|
1655
|
+
set amount(val: number);
|
|
1656
|
+
/**
|
|
1657
|
+
* Returns true on the first frame that the group collides with the
|
|
1658
|
+
* target group.
|
|
1659
|
+
*
|
|
1660
|
+
* Custom collision event handling can be done by using this function
|
|
1661
|
+
* in an if statement or adding a callback as the second parameter.
|
|
1662
|
+
*
|
|
1663
|
+
* @param target
|
|
1664
|
+
* @param callback
|
|
1665
|
+
*/
|
|
1666
|
+
collides(target: Group, callback?: Function): boolean;
|
|
1667
|
+
/**
|
|
1668
|
+
* Returns the amount of frames that the group has been colliding
|
|
1669
|
+
* with the target group for, which is a truthy value. Returns 0 if
|
|
1670
|
+
* the group is not colliding with the target group.
|
|
1671
|
+
*
|
|
1672
|
+
* @param target
|
|
1673
|
+
* @param callback
|
|
1674
|
+
* @return {Number} frames
|
|
1675
|
+
*/
|
|
1676
|
+
colliding(target: Group, callback?: Function): number;
|
|
1677
|
+
/**
|
|
1678
|
+
* Returns true on the first frame that the group no longer overlaps
|
|
1679
|
+
* with the target group.
|
|
1680
|
+
*
|
|
1681
|
+
* @param target
|
|
1682
|
+
* @param callback
|
|
1683
|
+
* @return {Boolean}
|
|
1684
|
+
*/
|
|
1685
|
+
collided(target: Group, callback?: Function): boolean;
|
|
1686
|
+
/**
|
|
1687
|
+
* Returns true on the first frame that the group overlaps with the
|
|
1688
|
+
* target group.
|
|
1689
|
+
*
|
|
1690
|
+
* Custom overlap event handling can be done by using this function
|
|
1691
|
+
* in an if statement or adding a callback as the second parameter.
|
|
1692
|
+
*
|
|
1693
|
+
* @param target
|
|
1694
|
+
* @param callback
|
|
1695
|
+
*/
|
|
1696
|
+
overlaps(target: Group, callback?: Function): boolean;
|
|
1697
|
+
/**
|
|
1698
|
+
* Returns the amount of frames that the group has been overlapping
|
|
1699
|
+
* with the target group for, which is a truthy value. Returns 0 if
|
|
1700
|
+
* the group is not overlapping with the target group.
|
|
1701
|
+
*
|
|
1702
|
+
* @param target
|
|
1703
|
+
* @param callback
|
|
1704
|
+
* @return {Number} frames
|
|
1705
|
+
*/
|
|
1706
|
+
overlapping(target: Group, callback?: Function): number;
|
|
1707
|
+
/**
|
|
1708
|
+
* Returns true on the first frame that the group no longer overlaps
|
|
1709
|
+
* with the target group.
|
|
1710
|
+
*
|
|
1711
|
+
* @param target
|
|
1712
|
+
* @param callback
|
|
1713
|
+
* @return {Boolean}
|
|
1714
|
+
*/
|
|
1715
|
+
overlapped(target: Group, callback?: Function): boolean;
|
|
1716
|
+
/**
|
|
1717
|
+
* Sets a pass through contact relationship between the group and the target group.
|
|
1718
|
+
* @param target
|
|
1719
|
+
*/
|
|
1720
|
+
pass(target: Group): void;
|
|
1721
|
+
/**
|
|
1722
|
+
* Sets a pass through contact relationship between the group and the target group.
|
|
1723
|
+
* @param target
|
|
1724
|
+
*/
|
|
1725
|
+
passes(target: Group): void;
|
|
1726
|
+
applyForce(amount: number, origin?: [] | { x: number; y: number } | Q5.Vector): void;
|
|
1727
|
+
applyForceScaled(amount: number, origin?: [] | { x: number; y: number } | Q5.Vector): void;
|
|
1728
|
+
attractTo(x: number | any, y?: number, force?: number): void;
|
|
1729
|
+
applyTorque(torque: any): void;
|
|
1730
|
+
moveTowards(x: number | any, y?: number, tracking?: number): void;
|
|
1731
|
+
moveAway(x: number | any, y?: number, repel?: number): void;
|
|
1732
|
+
repelFrom(x: number | any, y?: number, force?: number): void;
|
|
1733
|
+
/**
|
|
1734
|
+
* Detects when sprites go outside the given culling boundary
|
|
1735
|
+
* relative to the camera.
|
|
1736
|
+
*
|
|
1737
|
+
* By default, culled sprites are deleted, but a callback function
|
|
1738
|
+
* can be provided to perform other operations on the culled sprites.
|
|
1739
|
+
*
|
|
1740
|
+
* @param top the distance that sprites can move below the canvas before they are removed
|
|
1741
|
+
* @param bottom the distance that sprites can move below the canvas before they are removed
|
|
1742
|
+
* @param left the distance that sprites can move beyond the left side of the canvas before they are removed
|
|
1743
|
+
* @param right the distance that sprites can move beyond the right side of the canvas before they are removed
|
|
1744
|
+
* @param cb the function to be run when a sprite is culled,
|
|
1745
|
+
* it's given the sprite being culled, if no callback is given then the
|
|
1746
|
+
* sprite is removed
|
|
1747
|
+
* @return {Number} the number of sprites culled
|
|
1748
|
+
*/
|
|
1749
|
+
cull(top?: number, bottom?: number, left?: number, right?: number, cb?: Function): number;
|
|
1750
|
+
/**
|
|
1751
|
+
* If removalCount is greater than 0, that amount of
|
|
1752
|
+
* sprites starting from the start index will be removed
|
|
1753
|
+
* from this group and its sub groups recursively (if any),
|
|
1754
|
+
*
|
|
1755
|
+
* Then any provided sprites will be added at the start index
|
|
1756
|
+
* to this group and at the end of each of its parent groups recursively,
|
|
1757
|
+
* if not already present in parent groups.
|
|
1758
|
+
*
|
|
1759
|
+
* @param start start index
|
|
1760
|
+
* @param removalCount number of sprites to remove, starting from the start index
|
|
1761
|
+
* @param sprites sprites to add at start index
|
|
1762
|
+
* @return {Sprite[]} the removed sprites
|
|
1763
|
+
*/
|
|
1764
|
+
splice(start: number, removalCount: number, ...sprites: Sprite[]): Sprite[];
|
|
1765
|
+
/**
|
|
1766
|
+
* Removes a sprite from this group and its sub groups (if any),
|
|
1767
|
+
* but does not delete it from the world.
|
|
1768
|
+
*
|
|
1769
|
+
* @param item the sprite to be deleted or its index
|
|
1770
|
+
* @return {Sprite} the deleted sprite or undefined if the specified sprite was not found
|
|
1771
|
+
*/
|
|
1772
|
+
remove(item: Sprite | number): Sprite;
|
|
1773
|
+
/**
|
|
1774
|
+
* Deletes the group and all its sprites
|
|
1775
|
+
* from the world and every other group they belong to.
|
|
1776
|
+
*
|
|
1777
|
+
* Don't attempt to use a group after deleting it.
|
|
1778
|
+
*/
|
|
1779
|
+
delete(): void;
|
|
1780
|
+
/**
|
|
1781
|
+
* Deletes all the sprites in the group.
|
|
1782
|
+
*
|
|
1783
|
+
* Does not delete the group itself.
|
|
1784
|
+
*/
|
|
1785
|
+
deleteAll(): void;
|
|
1786
|
+
/**
|
|
1787
|
+
* Updates all the sprites in the group.
|
|
1788
|
+
*/
|
|
1789
|
+
update(): void;
|
|
1790
|
+
/**
|
|
1791
|
+
* Draws all the sprites in the group.
|
|
1792
|
+
*/
|
|
1793
|
+
draw(): void;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
class World {
|
|
1797
|
+
/**
|
|
1798
|
+
* Gravity force vector that affects all dynamic physics colliders.
|
|
1799
|
+
* @property {Number} x
|
|
1800
|
+
* @property {Number} y
|
|
1801
|
+
* @default { x: 0, y: 0 }
|
|
1802
|
+
*/
|
|
1803
|
+
get gravity(): any;
|
|
1804
|
+
set gravity(val: any);
|
|
1805
|
+
/**
|
|
1806
|
+
* The lowest velocity an object can have before it is considered
|
|
1807
|
+
* to be at rest.
|
|
1808
|
+
*
|
|
1809
|
+
* Adjust the bounce threshold to allow for slow moving objects
|
|
1810
|
+
* but don't have it be too low, or else objects will never sleep,
|
|
1811
|
+
* which will hurt performance.
|
|
1812
|
+
*
|
|
1813
|
+
* @default 0.19
|
|
1814
|
+
*/
|
|
1815
|
+
get bounceThreshold(): number;
|
|
1816
|
+
set bounceThreshold(val: number);
|
|
1817
|
+
/**
|
|
1818
|
+
* The time elapsed in the physics simulation in seconds.
|
|
1819
|
+
*/
|
|
1820
|
+
physicsTime: number;
|
|
1821
|
+
/**
|
|
1822
|
+
* Represents the size of a meter in pixels.
|
|
1823
|
+
*
|
|
1824
|
+
* Adjusting this property changes the simulated scale of the physics world.
|
|
1825
|
+
* For optimal results, it should be set such that sprites are between
|
|
1826
|
+
* 0.1 and 10 meters in size in the physics simulation.
|
|
1827
|
+
*
|
|
1828
|
+
* The default value is 60, which means that your sprites should optimally
|
|
1829
|
+
* be between 6 and 600 pixels in size.
|
|
1830
|
+
* @default 60
|
|
1831
|
+
*/
|
|
1832
|
+
meterSize: number;
|
|
1833
|
+
/**
|
|
1834
|
+
* @default true
|
|
1835
|
+
*/
|
|
1836
|
+
autoStep: boolean;
|
|
1837
|
+
/**
|
|
1838
|
+
* Performs a physics simulation step that advances all sprites
|
|
1839
|
+
* forward in time by 1 / updateRate * timeScale if no timeStep is given.
|
|
1840
|
+
*/
|
|
1841
|
+
physicsUpdate(timeStep?: number): void;
|
|
1842
|
+
/**
|
|
1843
|
+
* A time scale of 1.0 represents real time.
|
|
1844
|
+
* Accepts decimal values between 0 and 2.
|
|
1845
|
+
* @default 1.0
|
|
1846
|
+
*/
|
|
1847
|
+
get timeScale(): number;
|
|
1848
|
+
set timeScale(val: number);
|
|
1849
|
+
/**
|
|
1850
|
+
* The fixed update rate of the physics simulation in hertz.
|
|
1851
|
+
*
|
|
1852
|
+
* The time step, the amount of time that passes during a
|
|
1853
|
+
* physics update, is calculated to be: 1 / updateRate * timeScale
|
|
1854
|
+
*
|
|
1855
|
+
* Setting the update rate to a value lower than 50hz is not
|
|
1856
|
+
* recommended, as simulation quality will degrade.
|
|
1857
|
+
* @default 60
|
|
1858
|
+
*/
|
|
1859
|
+
get updateRate(): number;
|
|
1860
|
+
set updateRate(val: number);
|
|
1861
|
+
/**
|
|
1862
|
+
* The real time in seconds since the world was created, including
|
|
1863
|
+
* time spent paused.
|
|
1864
|
+
*/
|
|
1865
|
+
get realTime(): number;
|
|
1866
|
+
/**
|
|
1867
|
+
* Returns the sprites at a position, ordered by layer.
|
|
1868
|
+
*
|
|
1869
|
+
* Sprites must have a physics body to be detected.
|
|
1870
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
1871
|
+
* @param y
|
|
1872
|
+
* @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)
|
|
1873
|
+
* @param group limit results to a specific group,
|
|
1874
|
+
* allSprites by default
|
|
1875
|
+
* @param cameraActiveWhenDrawn limit results to
|
|
1876
|
+
* sprites drawn when the camera was active, true by default
|
|
1877
|
+
* @returns an array of sprites
|
|
1878
|
+
*/
|
|
1879
|
+
getSpritesAt(
|
|
1880
|
+
x: number | any,
|
|
1881
|
+
y?: number,
|
|
1882
|
+
radius?: number,
|
|
1883
|
+
group?: Group,
|
|
1884
|
+
cameraActiveWhenDrawn?: boolean
|
|
1885
|
+
): Sprite[];
|
|
1886
|
+
/**
|
|
1887
|
+
* Returns the sprite at the specified position
|
|
1888
|
+
* on the top most layer, drawn when the camera was on.
|
|
1889
|
+
*
|
|
1890
|
+
* The sprite must have a physics body to be detected.
|
|
1891
|
+
* @param x x coordinate or coordinate array or object with x and y properties
|
|
1892
|
+
* @param y
|
|
1893
|
+
* @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)
|
|
1894
|
+
* @param group the group to search
|
|
1895
|
+
* @returns a sprite
|
|
1896
|
+
*/
|
|
1897
|
+
getSpriteAt(x: number | any, y?: number, radius?: number, group?: Group): Sprite;
|
|
1898
|
+
/**
|
|
1899
|
+
* "Sleeping" sprites get temporarily ignored during physics
|
|
1900
|
+
* simulation. A sprite starts "sleeping" when it stops moving and
|
|
1901
|
+
* doesn't collide with anything that it wasn't already touching.
|
|
1902
|
+
*
|
|
1903
|
+
* This is an important performance optimization that you probably
|
|
1904
|
+
* shouldn't disable for every sprite in the world.
|
|
1905
|
+
* @default true
|
|
1906
|
+
*/
|
|
1907
|
+
get allowSleeping(): boolean;
|
|
1908
|
+
set allowSleeping(val: boolean);
|
|
1909
|
+
/**
|
|
1910
|
+
* Finds the first sprite (with a physics body) that
|
|
1911
|
+
* intersects a ray (line), excluding any sprites that intersect
|
|
1912
|
+
* with the starting point.
|
|
1913
|
+
*
|
|
1914
|
+
* @param startPos starting position of the ray cast
|
|
1915
|
+
* @param direction direction of the ray
|
|
1916
|
+
* @param maxDistance max distance the ray should check
|
|
1917
|
+
* @returns The first sprite the ray hits or undefined
|
|
1918
|
+
*/
|
|
1919
|
+
rayCast(startPos: any, direction: number, maxDistance: number): Sprite;
|
|
1920
|
+
/**
|
|
1921
|
+
* Finds sprites (with physics bodies) that intersect
|
|
1922
|
+
* a line (ray), excluding any sprites that intersect the
|
|
1923
|
+
* starting point.
|
|
1924
|
+
*
|
|
1925
|
+
* @param startPos starting position of the ray cast
|
|
1926
|
+
* @param direction direction of the ray
|
|
1927
|
+
* @param maxDistance max distance the ray should check
|
|
1928
|
+
* @param limiter limiter function that's run each time the ray intersects a sprite, return true to stop the ray
|
|
1929
|
+
* @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.
|
|
1930
|
+
*/
|
|
1931
|
+
rayCastAll(startPos: any, direction: number, maxDistance: number, limiter?: Function): Sprite[];
|
|
1932
|
+
/**
|
|
1933
|
+
* Applies an explosive force to sprites within the radius of the explosion.
|
|
1934
|
+
*
|
|
1935
|
+
* @param x x coordinate or coordinate array or object with x and y properties of the center of the explosion
|
|
1936
|
+
* @param y
|
|
1937
|
+
* @param radius the distance from the center of the explosion that sprites can be affected by the explosion
|
|
1938
|
+
* @param magnitude the strength of the explosion force, default is 1
|
|
1939
|
+
* @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)
|
|
1940
|
+
*/
|
|
1941
|
+
explodeAt(x: number | any, y?: number, radius?: number, magnitude?: number, falloff?: number): void;
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
class Camera {
|
|
1945
|
+
/**
|
|
1946
|
+
* Read only. True if the camera is active.
|
|
1947
|
+
* Use camera.on() to activate the camera.
|
|
1948
|
+
* @default false
|
|
1949
|
+
*/
|
|
1950
|
+
isActive: boolean;
|
|
1951
|
+
/**
|
|
1952
|
+
* The camera's position. {x, y}
|
|
1953
|
+
*/
|
|
1954
|
+
get pos(): any;
|
|
1955
|
+
set pos(val: any);
|
|
1956
|
+
/**
|
|
1957
|
+
* The camera's x position.
|
|
1958
|
+
*/
|
|
1959
|
+
get x(): number;
|
|
1960
|
+
set x(val: number);
|
|
1961
|
+
/**
|
|
1962
|
+
* The camera's y position.
|
|
1963
|
+
*/
|
|
1964
|
+
get y(): number;
|
|
1965
|
+
set y(val: number);
|
|
1966
|
+
/**
|
|
1967
|
+
* The camera's position. Alias for pos.
|
|
1968
|
+
*/
|
|
1969
|
+
get position(): any;
|
|
1970
|
+
set position(val: any);
|
|
1971
|
+
/**
|
|
1972
|
+
* Moves the camera to a position.
|
|
1973
|
+
*
|
|
1974
|
+
* @param x
|
|
1975
|
+
* @param y
|
|
1976
|
+
* @param speed
|
|
1977
|
+
* @returns resolves true when the camera reaches the target position
|
|
1978
|
+
*/
|
|
1979
|
+
moveTo(x: number, y: number, speed: number): Promise<boolean>;
|
|
1980
|
+
/**
|
|
1981
|
+
* Camera zoom.
|
|
1982
|
+
*
|
|
1983
|
+
* A scale of 1 will be the normal size. Setting it to 2
|
|
1984
|
+
* will make everything appear twice as big. .5 will make
|
|
1985
|
+
* everything look half size.
|
|
1986
|
+
* @default 1
|
|
1987
|
+
*/
|
|
1988
|
+
get zoom(): number;
|
|
1989
|
+
set zoom(val: number);
|
|
1990
|
+
/**
|
|
1991
|
+
* Zoom the camera at a given speed.
|
|
1992
|
+
*
|
|
1993
|
+
* @param target The target zoom
|
|
1994
|
+
* @param speed The amount of zoom per frame
|
|
1995
|
+
* @returns resolves true when the camera reaches the target zoom
|
|
1996
|
+
*/
|
|
1997
|
+
zoomTo(target: number, speed: number): Promise<boolean>;
|
|
1998
|
+
/**
|
|
1999
|
+
* Activates the camera.
|
|
2000
|
+
*
|
|
2001
|
+
* The canvas will be drawn according to the camera position and scale until
|
|
2002
|
+
* camera.off() is called.
|
|
2003
|
+
*/
|
|
2004
|
+
on(): void;
|
|
2005
|
+
/**
|
|
2006
|
+
* Deactivates the camera.
|
|
2007
|
+
*
|
|
2008
|
+
* The canvas will be drawn normally, ignoring the camera's position
|
|
2009
|
+
* and scale until camera.on() is called.
|
|
2010
|
+
*/
|
|
2011
|
+
off(): void;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
class Joint {
|
|
2015
|
+
/**
|
|
2016
|
+
* Joints are used to constrain the movement of two sprites relative
|
|
2017
|
+
* to each other. They can be used to create complex physics objects.
|
|
2018
|
+
*
|
|
2019
|
+
* Don't use the Joint constructor directly, use one of these
|
|
2020
|
+
* joint constructors instead:
|
|
2021
|
+
*
|
|
2022
|
+
* GlueJoint, DistanceJoint, WheelJoint, HingeJoint,
|
|
2023
|
+
* SliderJoint, or GrabberJoint.
|
|
2024
|
+
*
|
|
2025
|
+
* @param spriteA
|
|
2026
|
+
* @param spriteB
|
|
2027
|
+
* @param type
|
|
2028
|
+
*/
|
|
2029
|
+
constructor(spriteA: Sprite, spriteB: Sprite, type?: string);
|
|
2030
|
+
/**
|
|
2031
|
+
* The first sprite in the joint.
|
|
2032
|
+
*/
|
|
2033
|
+
spriteA: Sprite;
|
|
2034
|
+
/**
|
|
2035
|
+
* The second sprite in the joint.
|
|
2036
|
+
*/
|
|
2037
|
+
spriteB: Sprite;
|
|
2038
|
+
/**
|
|
2039
|
+
* The type of joint. Can be one of:
|
|
2040
|
+
*
|
|
2041
|
+
* "glue", "distance", "wheel", "hinge", "slider", or "grabber".
|
|
2042
|
+
*
|
|
2043
|
+
* Can't be changed after the joint is created.
|
|
2044
|
+
*/
|
|
2045
|
+
type: string;
|
|
2046
|
+
/**
|
|
2047
|
+
* Determines whether to draw the joint if spriteA
|
|
2048
|
+
* or spriteB is drawn.
|
|
2049
|
+
* @default true
|
|
2050
|
+
*/
|
|
2051
|
+
visible: boolean;
|
|
2052
|
+
/**
|
|
2053
|
+
* Offset to the joint's anchorA position from the center of spriteA.
|
|
2054
|
+
*
|
|
2055
|
+
* Only distance and hinge joints have an offsetA.
|
|
2056
|
+
* @default {x: 0, y: 0}
|
|
2057
|
+
*/
|
|
2058
|
+
get offsetA(): Q5.Vector;
|
|
2059
|
+
set offsetA(val: Q5.Vector);
|
|
2060
|
+
/**
|
|
2061
|
+
* Offset to the joint's anchorB position from the center of spriteB.
|
|
2062
|
+
*
|
|
2063
|
+
* Only distance, hinge, and wheel joints have an offsetB.
|
|
2064
|
+
* @default {x: 0, y: 0}
|
|
2065
|
+
*/
|
|
2066
|
+
get offsetB(): Q5.Vector;
|
|
2067
|
+
set offsetB(val: Q5.Vector);
|
|
2068
|
+
/**
|
|
2069
|
+
* Function that draws the joint. Can be overridden by the user.
|
|
2070
|
+
*/
|
|
2071
|
+
get draw(): Function;
|
|
2072
|
+
set draw(val: Function);
|
|
2073
|
+
/**
|
|
2074
|
+
* Set to true if you want the joint's sprites to collide with
|
|
2075
|
+
* each other.
|
|
2076
|
+
* @default false
|
|
2077
|
+
*/
|
|
2078
|
+
get collideConnected(): boolean;
|
|
2079
|
+
set collideConnected(val: boolean);
|
|
2080
|
+
/**
|
|
2081
|
+
* How much force the joint is applying to keep the two sprites together.
|
|
2082
|
+
* @readonly
|
|
2083
|
+
*/
|
|
2084
|
+
get reactionForce(): any;
|
|
2085
|
+
/**
|
|
2086
|
+
* How much torque the joint is applying to keep the two sprites together.
|
|
2087
|
+
* @readonly
|
|
2088
|
+
*/
|
|
2089
|
+
get reactionTorque(): any;
|
|
2090
|
+
/**
|
|
2091
|
+
* The amount of force that must be applied to the joint before it breaks.
|
|
2092
|
+
*
|
|
2093
|
+
* Setting the threshold too high leads to instability. Use
|
|
2094
|
+
* `sprite.addCollider` to simulate unbreakable bonds between shapes.
|
|
2095
|
+
* @default 500
|
|
2096
|
+
*/
|
|
2097
|
+
get forceThreshold(): number;
|
|
2098
|
+
set forceThreshold(val: number);
|
|
2099
|
+
/**
|
|
2100
|
+
* The amount of torque that must be applied to the joint before it breaks.
|
|
2101
|
+
*
|
|
2102
|
+
* Setting the threshold too high leads to instability. Use
|
|
2103
|
+
* `sprite.addCollider` to simulate unbreakable bonds between shapes.
|
|
2104
|
+
* @default 500
|
|
2105
|
+
*/
|
|
2106
|
+
get torqueThreshold(): number;
|
|
2107
|
+
set torqueThreshold(val: number);
|
|
2108
|
+
/**
|
|
2109
|
+
* This function is run when the joint's reaction force exceeds the
|
|
2110
|
+
* force threshold or its reaction torque exceeds the torque threshold.
|
|
2111
|
+
*
|
|
2112
|
+
* By default, the sprites' speed and rotation speed are set to 0
|
|
2113
|
+
* and the joint is deleted, simulating a break.
|
|
2114
|
+
*/
|
|
2115
|
+
onStrain(): void;
|
|
2116
|
+
/**
|
|
2117
|
+
* Deletes the joint from the world and from each of the
|
|
2118
|
+
* associated sprites' joints arrays.
|
|
2119
|
+
*/
|
|
2120
|
+
delete(): void;
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
class GlueJoint extends Joint {
|
|
2124
|
+
/**
|
|
2125
|
+
* Glue joints are used to glue two sprites together.
|
|
2126
|
+
*
|
|
2127
|
+
* @param spriteA
|
|
2128
|
+
* @param spriteB
|
|
2129
|
+
*/
|
|
2130
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2131
|
+
get springiness(): number;
|
|
2132
|
+
set springiness(val: number);
|
|
2133
|
+
get damping(): number;
|
|
2134
|
+
set damping(val: number);
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
class DistanceJoint extends Joint {
|
|
2138
|
+
/**
|
|
2139
|
+
* Distance joints are used to constrain the distance
|
|
2140
|
+
* between two sprites.
|
|
2141
|
+
*
|
|
2142
|
+
* @param spriteA
|
|
2143
|
+
* @param spriteB
|
|
2144
|
+
*/
|
|
2145
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2146
|
+
/**
|
|
2147
|
+
* The current distance between the two joint anchors.
|
|
2148
|
+
* @readonly
|
|
2149
|
+
*/
|
|
2150
|
+
get currentLength(): number;
|
|
2151
|
+
/**
|
|
2152
|
+
* The target length of the joint between the two joint anchors.
|
|
2153
|
+
*
|
|
2154
|
+
* It's set to the current distance between the two sprites
|
|
2155
|
+
* when the joint is created.
|
|
2156
|
+
*/
|
|
2157
|
+
get length(): number;
|
|
2158
|
+
set length(val: number);
|
|
2159
|
+
/**
|
|
2160
|
+
* Whether the joint's length limits are enabled.
|
|
2161
|
+
* When enabled a min/max length range constrains the joint.
|
|
2162
|
+
* @default false
|
|
2163
|
+
*/
|
|
2164
|
+
get limitsEnabled(): boolean;
|
|
2165
|
+
set limitsEnabled(val: boolean);
|
|
2166
|
+
/**
|
|
2167
|
+
* The minimum length allowed when limits are enabled.
|
|
2168
|
+
*/
|
|
2169
|
+
get minLength(): number;
|
|
2170
|
+
/**
|
|
2171
|
+
* The maximum length allowed when limits are enabled.
|
|
2172
|
+
*/
|
|
2173
|
+
get maxLength(): number;
|
|
2174
|
+
/**
|
|
2175
|
+
* Accepts an array that contains the minimum and maximum length limits.
|
|
2176
|
+
*/
|
|
2177
|
+
set range(val: [number, number]);
|
|
2178
|
+
/**
|
|
2179
|
+
* Whether spring behavior is enabled for the joint.
|
|
2180
|
+
* @default true
|
|
2181
|
+
*/
|
|
2182
|
+
get springEnabled(): boolean;
|
|
2183
|
+
set springEnabled(val: boolean);
|
|
2184
|
+
/**
|
|
2185
|
+
* The springiness of the joint, a 0-1 ratio.
|
|
2186
|
+
*
|
|
2187
|
+
* 0 is rigid, 0.5 is bouncy, 1 is loose.
|
|
2188
|
+
* @default 0
|
|
2189
|
+
*/
|
|
2190
|
+
get springiness(): number;
|
|
2191
|
+
set springiness(val: number);
|
|
2192
|
+
/**
|
|
2193
|
+
* Damping is a 0-1 ratio describing how quickly the joint loses
|
|
2194
|
+
* vibrational energy.
|
|
2195
|
+
*
|
|
2196
|
+
* 0.0 means no damping, 1.0 means critical damping, which will stop
|
|
2197
|
+
* the joint from vibrating at all.
|
|
2198
|
+
*
|
|
2199
|
+
* Damping only effects joints that have a
|
|
2200
|
+
* springiness greater than 0.
|
|
2201
|
+
* @default 0.0
|
|
2202
|
+
*/
|
|
2203
|
+
get damping(): number;
|
|
2204
|
+
set damping(val: number);
|
|
2205
|
+
/**
|
|
2206
|
+
* Whether the joint's motor is enabled.
|
|
2207
|
+
* @default false
|
|
2208
|
+
*/
|
|
2209
|
+
get motorEnabled(): boolean;
|
|
2210
|
+
set motorEnabled(val: boolean);
|
|
2211
|
+
/**
|
|
2212
|
+
* Motor speed.
|
|
2213
|
+
* @default 0
|
|
2214
|
+
*/
|
|
2215
|
+
get speed(): number;
|
|
2216
|
+
set speed(val: number);
|
|
2217
|
+
/**
|
|
2218
|
+
* Maximum motor force the motor can apply.
|
|
2219
|
+
*/
|
|
2220
|
+
get maxPower(): number;
|
|
2221
|
+
set maxPower(val: number);
|
|
2222
|
+
/**
|
|
2223
|
+
* The current motor force being applied by the joint.
|
|
2224
|
+
* @readonly
|
|
2225
|
+
*/
|
|
2226
|
+
get power(): number;
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
class WheelJoint extends Joint {
|
|
2230
|
+
/**
|
|
2231
|
+
* Wheel joints can be used to create vehicles!
|
|
2232
|
+
*
|
|
2233
|
+
* By default `motorEnabled` is false, `angle` is 90 degrees,
|
|
2234
|
+
* `maxPower` is 1000, `springiness` is 0.1, and `damping` is 0.7.
|
|
2235
|
+
*
|
|
2236
|
+
* @param spriteA the vehicle body
|
|
2237
|
+
* @param spriteB the wheel
|
|
2238
|
+
*/
|
|
2239
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2240
|
+
/**
|
|
2241
|
+
* The angle at which the wheel is attached to the vehicle body.
|
|
2242
|
+
*
|
|
2243
|
+
* The default is 90 degrees (PI/2 in radians).
|
|
2244
|
+
* @default 90
|
|
2245
|
+
*/
|
|
2246
|
+
get angle(): number;
|
|
2247
|
+
set angle(val: number);
|
|
2248
|
+
/**
|
|
2249
|
+
* The current distance between the two joint anchors.
|
|
2250
|
+
* @readonly
|
|
2251
|
+
*/
|
|
2252
|
+
get currentLength(): number;
|
|
2253
|
+
/**
|
|
2254
|
+
* The target length of the joint between the two joint anchors.
|
|
2255
|
+
*
|
|
2256
|
+
* It's set to the current distance between the two sprites
|
|
2257
|
+
* when the joint is created.
|
|
2258
|
+
*/
|
|
2259
|
+
get length(): number;
|
|
2260
|
+
set length(val: number);
|
|
2261
|
+
/**
|
|
2262
|
+
* Whether the joint's length limits are enabled.
|
|
2263
|
+
* When enabled a min/max length range constrains the joint.
|
|
2264
|
+
* @default false
|
|
2265
|
+
*/
|
|
2266
|
+
get limitsEnabled(): boolean;
|
|
2267
|
+
set limitsEnabled(val: boolean);
|
|
2268
|
+
/**
|
|
2269
|
+
* The minimum length allowed when limits are enabled.
|
|
2270
|
+
*/
|
|
2271
|
+
get minLength(): number;
|
|
2272
|
+
/**
|
|
2273
|
+
* The maximum length allowed when limits are enabled.
|
|
2274
|
+
*/
|
|
2275
|
+
get maxLength(): number;
|
|
2276
|
+
/**
|
|
2277
|
+
* Accepts an array that contains the minimum and maximum length limits.
|
|
2278
|
+
*/
|
|
2279
|
+
set range(val: [number, number]);
|
|
2280
|
+
/**
|
|
2281
|
+
* Whether spring behavior is enabled for the joint.
|
|
2282
|
+
* @default true
|
|
2283
|
+
*/
|
|
2284
|
+
get springEnabled(): boolean;
|
|
2285
|
+
set springEnabled(val: boolean);
|
|
2286
|
+
/**
|
|
2287
|
+
* The springiness of the joint, a 0-1 ratio.
|
|
2288
|
+
*
|
|
2289
|
+
* 0.0 is rigid, 0.5 is bouncy, 1.0 is loose.
|
|
2290
|
+
* @default 0.0
|
|
2291
|
+
*/
|
|
2292
|
+
get springiness(): number;
|
|
2293
|
+
set springiness(val: number);
|
|
2294
|
+
/**
|
|
2295
|
+
* Damping is a 0-1 ratio describing how quickly the joint loses
|
|
2296
|
+
* vibrational energy.
|
|
2297
|
+
*
|
|
2298
|
+
* 0.0 means no damping, 1.0 means critical damping, which will stop
|
|
2299
|
+
* the joint from vibrating at all.
|
|
2300
|
+
*
|
|
2301
|
+
* Damping only effects joints that have a
|
|
2302
|
+
* springiness greater than 0.
|
|
2303
|
+
* @default 0.0
|
|
2304
|
+
*/
|
|
2305
|
+
get damping(): number;
|
|
2306
|
+
set damping(val: number);
|
|
2307
|
+
/**
|
|
2308
|
+
* Whether the joint's motor is enabled.
|
|
2309
|
+
* @default false
|
|
2310
|
+
*/
|
|
2311
|
+
get motorEnabled(): boolean;
|
|
2312
|
+
set motorEnabled(val: boolean);
|
|
2313
|
+
/**
|
|
2314
|
+
* Motor speed.
|
|
2315
|
+
* @default 0
|
|
2316
|
+
*/
|
|
2317
|
+
get speed(): number;
|
|
2318
|
+
set speed(val: number);
|
|
2319
|
+
/**
|
|
2320
|
+
* Maximum torque the motor can apply.
|
|
2321
|
+
*/
|
|
2322
|
+
get maxPower(): number;
|
|
2323
|
+
set maxPower(val: number);
|
|
2324
|
+
/**
|
|
2325
|
+
* The current torque being applied by the motor.
|
|
2326
|
+
* @readonly
|
|
2327
|
+
*/
|
|
2328
|
+
get power(): number;
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
class HingeJoint extends Joint {
|
|
2332
|
+
/**
|
|
2333
|
+
* Hinge joints attach two sprites together at a pivot point,
|
|
2334
|
+
* constraining them to rotate around this point, like a hinge.
|
|
2335
|
+
*
|
|
2336
|
+
* A known as a revolute joint.
|
|
2337
|
+
*
|
|
2338
|
+
* @param spriteA
|
|
2339
|
+
* @param spriteB
|
|
2340
|
+
*/
|
|
2341
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2342
|
+
/**
|
|
2343
|
+
* Whether the joint's angle limits are enabled.
|
|
2344
|
+
* When enabled a min/max angle range constrains the joint.
|
|
2345
|
+
* @default false
|
|
2346
|
+
*/
|
|
2347
|
+
get limitsEnabled(): boolean;
|
|
2348
|
+
set limitsEnabled(val: boolean);
|
|
2349
|
+
/**
|
|
2350
|
+
* The lower limit of rotation.
|
|
2351
|
+
* @default undefined
|
|
2352
|
+
*/
|
|
2353
|
+
get minAngle(): number;
|
|
2354
|
+
/**
|
|
2355
|
+
* The upper limit of rotation.
|
|
2356
|
+
* @default undefined
|
|
2357
|
+
*/
|
|
2358
|
+
get maxAngle(): number;
|
|
2359
|
+
/**
|
|
2360
|
+
* Accepts an array that contains the lower and upper limits of rotation.
|
|
2361
|
+
*/
|
|
2362
|
+
set range(val: [number, number]);
|
|
2363
|
+
/**
|
|
2364
|
+
* Read only. The joint's current angle of rotation.
|
|
2365
|
+
*/
|
|
2366
|
+
get angle(): number;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
class SliderJoint extends Joint {
|
|
2370
|
+
/**
|
|
2371
|
+
* A slider joint constrains the motion of two sprites to sliding
|
|
2372
|
+
* along a common axis, without rotation.
|
|
2373
|
+
*
|
|
2374
|
+
* Also known as a prismatic joint.
|
|
2375
|
+
*
|
|
2376
|
+
* @param spriteA
|
|
2377
|
+
* @param spriteB
|
|
2378
|
+
*/
|
|
2379
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2380
|
+
/**
|
|
2381
|
+
* The joint's range of translation. Setting the range
|
|
2382
|
+
* changes the joint's upper and lower limits.
|
|
2383
|
+
* @default undefined
|
|
2384
|
+
*/
|
|
2385
|
+
get range(): number;
|
|
2386
|
+
set range(val: number);
|
|
2387
|
+
/**
|
|
2388
|
+
* The mathematical upper (not positionally higher)
|
|
2389
|
+
* limit of translation.
|
|
2390
|
+
* @default undefined
|
|
2391
|
+
*/
|
|
2392
|
+
get upperLimit(): number;
|
|
2393
|
+
set upperLimit(val: number);
|
|
2394
|
+
/**
|
|
2395
|
+
* The mathematical lower (not positionally lower)
|
|
2396
|
+
* limit of translation.
|
|
2397
|
+
* @default undefined
|
|
2398
|
+
*/
|
|
2399
|
+
get lowerLimit(): number;
|
|
2400
|
+
set lowerLimit(val: number);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
class RopeJoint extends Joint {
|
|
2404
|
+
/**
|
|
2405
|
+
* A Rope joint prevents two sprites from going further
|
|
2406
|
+
* than a certain distance from each other, which is
|
|
2407
|
+
* defined by the max length of the rope, but they do allow
|
|
2408
|
+
* the sprites to get closer together.
|
|
2409
|
+
*
|
|
2410
|
+
* @param spriteA
|
|
2411
|
+
* @param spriteB
|
|
2412
|
+
*/
|
|
2413
|
+
constructor(spriteA: Sprite, spriteB: Sprite);
|
|
2414
|
+
/**
|
|
2415
|
+
* The maximum length of the rope.
|
|
2416
|
+
*/
|
|
2417
|
+
get maxLength(): number;
|
|
2418
|
+
set maxLength(val: number);
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
class GrabberJoint extends Joint {
|
|
2422
|
+
/**
|
|
2423
|
+
* A Grabber joint enables you to grab sprites and move them with
|
|
2424
|
+
* a max force towards a target position.
|
|
2425
|
+
*
|
|
2426
|
+
* @param pointer the point at which the sprite is grabbed
|
|
2427
|
+
* @param sprite the sprite to grab
|
|
2428
|
+
*/
|
|
2429
|
+
constructor(pointer: any, sprite: Sprite);
|
|
2430
|
+
/**
|
|
2431
|
+
* The sprite being grabbed by the joint.
|
|
2432
|
+
*/
|
|
2433
|
+
sprite: Sprite;
|
|
2434
|
+
/**
|
|
2435
|
+
* The target position of the joint that the sprite will be
|
|
2436
|
+
* moved towards. Can be a coordinate array or object with x and y properties.
|
|
2437
|
+
*/
|
|
2438
|
+
get target(): any;
|
|
2439
|
+
set target(pos: any);
|
|
2440
|
+
/**
|
|
2441
|
+
* The maximum spring force that the joint can exert on the sprite.
|
|
2442
|
+
*
|
|
2443
|
+
* By default it's 500 * the sprite's mass.
|
|
2444
|
+
*/
|
|
2445
|
+
get maxForce(): number;
|
|
2446
|
+
set maxForce(val: number);
|
|
2447
|
+
/**
|
|
2448
|
+
* The maximum torque that the joint can exert on the sprite.
|
|
2449
|
+
*
|
|
2450
|
+
* By default it's 0.25 * the sprite's mass * the square root
|
|
2451
|
+
* of the rotational inertia divided by the sprite's mass.
|
|
2452
|
+
*/
|
|
2453
|
+
get maxTorque(): number;
|
|
2454
|
+
set maxTorque(val: number);
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
class Scale {
|
|
2458
|
+
valueOf(): number;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
/**
|
|
2462
|
+
* A FriendlyError is a custom error class that extends the native JS
|
|
2463
|
+
* Error class. It's used internally by q5play to make error messages
|
|
2464
|
+
* more helpful.
|
|
2465
|
+
*
|
|
2466
|
+
* @private
|
|
2467
|
+
* @param func the name of the function the error was thrown in
|
|
2468
|
+
* @param errorNum the error's code number
|
|
2469
|
+
* @param e an array of values relevant to the error
|
|
2470
|
+
*/
|
|
2471
|
+
class FriendlyError extends Error {
|
|
2472
|
+
constructor(func: any, errorNum: any, e: any);
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
class InputDevice {
|
|
2476
|
+
/**
|
|
2477
|
+
* The amount of frames an input must be pressed to be considered held.
|
|
2478
|
+
* @default 12
|
|
2479
|
+
*/
|
|
2480
|
+
holdThreshold: number;
|
|
2481
|
+
/**
|
|
2482
|
+
* @param inp
|
|
2483
|
+
* @returns true on the first frame that the user presses the input
|
|
2484
|
+
*/
|
|
2485
|
+
presses(inp?: string): boolean;
|
|
2486
|
+
/**
|
|
2487
|
+
* @param inp
|
|
2488
|
+
* @returns the amount of frames the user has been pressing the input
|
|
2489
|
+
*/
|
|
2490
|
+
pressing(inp?: string): number;
|
|
2491
|
+
/**
|
|
2492
|
+
* Same as the `released` function, which is preferred.
|
|
2493
|
+
* @deprecated
|
|
2494
|
+
* @param inp
|
|
2495
|
+
* @returns true on the first frame that the user released the input
|
|
2496
|
+
*/
|
|
2497
|
+
pressed(inp?: string): boolean;
|
|
2498
|
+
/**
|
|
2499
|
+
* @param inp
|
|
2500
|
+
* @returns true on the first frame that the user holds the input
|
|
2501
|
+
*/
|
|
2502
|
+
holds(inp?: string): boolean;
|
|
2503
|
+
/**
|
|
2504
|
+
* @param inp
|
|
2505
|
+
* @returns the amount of frames the user has been holding the input
|
|
2506
|
+
*/
|
|
2507
|
+
holding(inp?: string): number;
|
|
2508
|
+
/**
|
|
2509
|
+
* @param inp
|
|
2510
|
+
* @returns true on the first frame that the user released a held input
|
|
2511
|
+
*/
|
|
2512
|
+
held(inp?: string): boolean;
|
|
2513
|
+
/**
|
|
2514
|
+
* @param inp
|
|
2515
|
+
* @returns true on the first frame that the user released the input
|
|
2516
|
+
*/
|
|
2517
|
+
released(inp?: string): boolean;
|
|
2518
|
+
releases(inp?: any): boolean;
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
class _Mouse extends InputDevice {
|
|
2522
|
+
/**
|
|
2523
|
+
* The mouse's x position in the world.
|
|
2524
|
+
*/
|
|
2525
|
+
x: number;
|
|
2526
|
+
/**
|
|
2527
|
+
* The mouse's y position in the world.
|
|
2528
|
+
*/
|
|
2529
|
+
y: number;
|
|
2530
|
+
/**
|
|
2531
|
+
* The mouse's absolute position on the canvas.
|
|
2532
|
+
* @property {Number} x
|
|
2533
|
+
* @property {Number} y
|
|
2534
|
+
*/
|
|
2535
|
+
canvasPos: { x: number; y: number };
|
|
2536
|
+
/**
|
|
2537
|
+
* The mouse's left button.
|
|
2538
|
+
*/
|
|
2539
|
+
left: number;
|
|
2540
|
+
/**
|
|
2541
|
+
* The mouse's center button.
|
|
2542
|
+
*/
|
|
2543
|
+
center: number;
|
|
2544
|
+
/**
|
|
2545
|
+
* The mouse's right button.
|
|
2546
|
+
*/
|
|
2547
|
+
right: number;
|
|
2548
|
+
/**
|
|
2549
|
+
* Contains the scroll status of the mouse wheel.
|
|
2550
|
+
* @property {Number} x the horizontal scroll amount
|
|
2551
|
+
* @property {Number} y the vertical scroll amount
|
|
2552
|
+
*/
|
|
2553
|
+
scrollDelta: { x: number; y: number };
|
|
2554
|
+
/**
|
|
2555
|
+
* Contains the drag status of each of the mouse's buttons.
|
|
2556
|
+
*/
|
|
2557
|
+
drag: {};
|
|
2558
|
+
/**
|
|
2559
|
+
* True if the mouse is currently on the canvas.
|
|
2560
|
+
* @default false
|
|
2561
|
+
*/
|
|
2562
|
+
isOnCanvas: boolean;
|
|
2563
|
+
/**
|
|
2564
|
+
* True if the mouse has ever interacted with the canvas.
|
|
2565
|
+
* @default false
|
|
2566
|
+
*/
|
|
2567
|
+
isActive: boolean;
|
|
2568
|
+
/**
|
|
2569
|
+
* The mouse's position.
|
|
2570
|
+
*/
|
|
2571
|
+
get pos(): {};
|
|
2572
|
+
/**
|
|
2573
|
+
* The mouse's position. Alias for pos.
|
|
2574
|
+
*/
|
|
2575
|
+
get position(): {};
|
|
2576
|
+
/**
|
|
2577
|
+
* The mouse's CSS cursor style.
|
|
2578
|
+
* @default 'default'
|
|
2579
|
+
*/
|
|
2580
|
+
get cursor(): string;
|
|
2581
|
+
set cursor(val: string);
|
|
2582
|
+
/**
|
|
2583
|
+
* Controls whether the mouse is visible or not.
|
|
2584
|
+
* @default true
|
|
2585
|
+
*/
|
|
2586
|
+
get visible(): boolean;
|
|
2587
|
+
set visible(val: boolean);
|
|
2588
|
+
/**
|
|
2589
|
+
* @param inp
|
|
2590
|
+
* @returns true on the first frame that the user moves the mouse while pressing the input
|
|
2591
|
+
*/
|
|
2592
|
+
drags(inp?: string): boolean;
|
|
2593
|
+
/**
|
|
2594
|
+
* @param inp
|
|
2595
|
+
* @returns the amount of frames the user has been moving the mouse while pressing the input
|
|
2596
|
+
*/
|
|
2597
|
+
dragging(inp?: string): number;
|
|
2598
|
+
/**
|
|
2599
|
+
* @param inp
|
|
2600
|
+
* @returns true on the first frame that the user releases the input after dragging the mouse
|
|
2601
|
+
*/
|
|
2602
|
+
dragged(inp?: string): boolean;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
class _Pointer extends InputDevice {
|
|
2606
|
+
constructor(pointer: any);
|
|
2607
|
+
/**
|
|
2608
|
+
* The pointer's x position in the physics world.
|
|
2609
|
+
*/
|
|
2610
|
+
x: number;
|
|
2611
|
+
/**
|
|
2612
|
+
* The pointer's y position in the physics world.
|
|
2613
|
+
*/
|
|
2614
|
+
y: number;
|
|
2615
|
+
/**
|
|
2616
|
+
* The pointer's unique identifier.
|
|
2617
|
+
*/
|
|
2618
|
+
id: number;
|
|
2619
|
+
/**
|
|
2620
|
+
* The amount of frames the pointer has been active for.
|
|
2621
|
+
*/
|
|
2622
|
+
duration: number;
|
|
2623
|
+
/**
|
|
2624
|
+
* The pointer's absolute position on the canvas.
|
|
2625
|
+
*/
|
|
2626
|
+
canvasPos: { x: number; y: number };
|
|
2627
|
+
/**
|
|
2628
|
+
* The pointer's pressure level, from 0 to 1.
|
|
2629
|
+
*
|
|
2630
|
+
* On devices that do not support pressure sensitivity,
|
|
2631
|
+
* the value is 0.5 when the pointer is pressing.
|
|
2632
|
+
*/
|
|
2633
|
+
pressure: number;
|
|
2634
|
+
/**
|
|
2635
|
+
* The amount of frames the user has been clicking, touching,
|
|
2636
|
+
* or drawing on the screen with the pointer.
|
|
2637
|
+
*/
|
|
2638
|
+
press: number;
|
|
2639
|
+
/**
|
|
2640
|
+
* @returns true on the first frame that the pointer grabs a sprite
|
|
2641
|
+
*/
|
|
2642
|
+
grabs(): boolean;
|
|
2643
|
+
/**
|
|
2644
|
+
* @returns the amount of frames the pointer has been grabbing a sprite
|
|
2645
|
+
*/
|
|
2646
|
+
grabbing(): number;
|
|
2647
|
+
/**
|
|
2648
|
+
* @returns true on the first frame that the pointer releases a grabbed sprite
|
|
2649
|
+
*/
|
|
2650
|
+
grabbed(): boolean;
|
|
2651
|
+
/**
|
|
2652
|
+
* @param sprite
|
|
2653
|
+
* @returns true on the first frame that the pointer overlaps the sprite
|
|
2654
|
+
*/
|
|
2655
|
+
overlaps(sprite: Sprite): boolean;
|
|
2656
|
+
/**
|
|
2657
|
+
* @param sprite
|
|
2658
|
+
* @returns the amount of frames the pointer has been overlapping the sprite
|
|
2659
|
+
*/
|
|
2660
|
+
overlapping(sprite: Sprite): number;
|
|
2661
|
+
/**
|
|
2662
|
+
* @param sprite
|
|
2663
|
+
* @returns true on the first frame that the pointer stops overlapping the sprite
|
|
2664
|
+
*/
|
|
2665
|
+
overlapped(sprite: Sprite): boolean;
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
class _Keyboard extends InputDevice {
|
|
2669
|
+
alt: number;
|
|
2670
|
+
arrowUp: number;
|
|
2671
|
+
arrowDown: number;
|
|
2672
|
+
arrowLeft: number;
|
|
2673
|
+
arrowRight: number;
|
|
2674
|
+
backspace: number;
|
|
2675
|
+
capsLock: number;
|
|
2676
|
+
control: number;
|
|
2677
|
+
enter: number;
|
|
2678
|
+
meta: number;
|
|
2679
|
+
shift: number;
|
|
2680
|
+
tab: number;
|
|
2681
|
+
get visible(): boolean;
|
|
2682
|
+
set visible(v: boolean);
|
|
2683
|
+
get cmd(): number;
|
|
2684
|
+
get command(): number;
|
|
2685
|
+
get ctrl(): number;
|
|
2686
|
+
get space(): any;
|
|
2687
|
+
get opt(): number;
|
|
2688
|
+
get option(): number;
|
|
2689
|
+
get win(): number;
|
|
2690
|
+
get windows(): number;
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
class Contro extends InputDevice {
|
|
2694
|
+
/**
|
|
2695
|
+
* Stores the input status of buttons, triggers, and sticks on
|
|
2696
|
+
* game controllers. Used internally to create controller objects
|
|
2697
|
+
* for the `contros` array (aka `controllers`).
|
|
2698
|
+
*
|
|
2699
|
+
* Can also be used to create a mock controller object.
|
|
2700
|
+
* @param gamepad gamepad object or id string for a mock controller
|
|
2701
|
+
*/
|
|
2702
|
+
constructor(gp: Gamepad | string);
|
|
2703
|
+
connected: boolean;
|
|
2704
|
+
a: number;
|
|
2705
|
+
b: number;
|
|
2706
|
+
x: number;
|
|
2707
|
+
y: number;
|
|
2708
|
+
/**
|
|
2709
|
+
* Left shoulder button.
|
|
2710
|
+
*/
|
|
2711
|
+
l: number;
|
|
2712
|
+
/**
|
|
2713
|
+
* Right shoulder button.
|
|
2714
|
+
*/
|
|
2715
|
+
r: number;
|
|
2716
|
+
/**
|
|
2717
|
+
* Digital left trigger.
|
|
2718
|
+
*/
|
|
2719
|
+
lt: number;
|
|
2720
|
+
/**
|
|
2721
|
+
* Digital right trigger.
|
|
2722
|
+
*/
|
|
2723
|
+
rt: number;
|
|
2724
|
+
select: number;
|
|
2725
|
+
start: number;
|
|
2726
|
+
/**
|
|
2727
|
+
* Left stick button.
|
|
2728
|
+
* Activated by pressing down on the left analog stick.
|
|
2729
|
+
*/
|
|
2730
|
+
lsb: number;
|
|
2731
|
+
/**
|
|
2732
|
+
* Right stick button.
|
|
2733
|
+
* Activated by pressing down on the right analog stick.
|
|
2734
|
+
*/
|
|
2735
|
+
rsb: number;
|
|
2736
|
+
up: number;
|
|
2737
|
+
down: number;
|
|
2738
|
+
left: number;
|
|
2739
|
+
right: number;
|
|
2740
|
+
/**
|
|
2741
|
+
* Has x and y properties with -1 to 1 values which
|
|
2742
|
+
* represent the position of the left analog stick.
|
|
2743
|
+
*
|
|
2744
|
+
* {x: 0, y: 0} is the center position.
|
|
2745
|
+
*/
|
|
2746
|
+
leftStick: any;
|
|
2747
|
+
/**
|
|
2748
|
+
* Has x and y properties with -1 to 1 values which
|
|
2749
|
+
* represent the position of the right analog stick.
|
|
2750
|
+
*
|
|
2751
|
+
* {x: 0, y: 0} is the center position.
|
|
2752
|
+
*/
|
|
2753
|
+
rightStick: any;
|
|
2754
|
+
/**
|
|
2755
|
+
* Analog value 0-1 of the left trigger.
|
|
2756
|
+
* @default 0
|
|
2757
|
+
*/
|
|
2758
|
+
leftTrigger: number;
|
|
2759
|
+
/**
|
|
2760
|
+
* Analog value 0-1 of the right trigger.
|
|
2761
|
+
* @default 0
|
|
2762
|
+
*/
|
|
2763
|
+
rightTrigger: number;
|
|
2764
|
+
/**
|
|
2765
|
+
* Button names are mapped to `gamepad.buttons` indices.
|
|
2766
|
+
*/
|
|
2767
|
+
buttonMapping: any;
|
|
2768
|
+
/**
|
|
2769
|
+
* Sticks and triggers are mapped to `gamepad.axes` indices.
|
|
2770
|
+
*/
|
|
2771
|
+
axeMapping: any;
|
|
2772
|
+
/**
|
|
2773
|
+
* If the controller is a mock controller.
|
|
2774
|
+
*/
|
|
2775
|
+
isMock: boolean;
|
|
2776
|
+
gamepad: Gamepad;
|
|
2777
|
+
id: any;
|
|
2778
|
+
/**
|
|
2779
|
+
* True if the controller has analog triggers.
|
|
2780
|
+
* False if the controller has digital (button) triggers.
|
|
2781
|
+
*/
|
|
2782
|
+
hasAnalogTriggers: boolean;
|
|
2783
|
+
get cross(): number;
|
|
2784
|
+
get circle(): number;
|
|
2785
|
+
get square(): number;
|
|
2786
|
+
get triangle(): number;
|
|
2787
|
+
/**
|
|
2788
|
+
* Alias for `leftStick`.
|
|
2789
|
+
*/
|
|
2790
|
+
get ls(): any;
|
|
2791
|
+
/**
|
|
2792
|
+
* Alias for `rightStick`.
|
|
2793
|
+
*/
|
|
2794
|
+
get rs(): any;
|
|
2795
|
+
/**
|
|
2796
|
+
* Alias for `l` (left shoulder button).
|
|
2797
|
+
* `lb` is what it's called on Xbox controllers.
|
|
2798
|
+
*/
|
|
2799
|
+
get lb(): number;
|
|
2800
|
+
/**
|
|
2801
|
+
* Alias for `r` (right shoulder button).
|
|
2802
|
+
* `rb` is what it's called on Xbox controllers.
|
|
2803
|
+
*/
|
|
2804
|
+
get rb(): number;
|
|
2805
|
+
/**
|
|
2806
|
+
* Alias for `l` (left shoulder button).
|
|
2807
|
+
* `l1` is what it's called on PlayStation controllers.
|
|
2808
|
+
*/
|
|
2809
|
+
get l1(): number;
|
|
2810
|
+
/**
|
|
2811
|
+
* Alias for `r` (right shoulder button).
|
|
2812
|
+
* `r1` is what it's called on PlayStation controllers.
|
|
2813
|
+
*/
|
|
2814
|
+
get r1(): number;
|
|
2815
|
+
/**
|
|
2816
|
+
* Alias for `lt` (digital left trigger).
|
|
2817
|
+
* `zl` is what it's called on Nintendo controllers.
|
|
2818
|
+
*/
|
|
2819
|
+
get zl(): number;
|
|
2820
|
+
/**
|
|
2821
|
+
* Alias for `rt` (digital right trigger).
|
|
2822
|
+
* `zr` is what it's called on Nintendo controllers.
|
|
2823
|
+
*/
|
|
2824
|
+
get zr(): number;
|
|
2825
|
+
/**
|
|
2826
|
+
* Alias for `leftTrigger` (analog left trigger).
|
|
2827
|
+
* `l2` is what it's called on PlayStation controllers.
|
|
2828
|
+
*/
|
|
2829
|
+
get l2(): number;
|
|
2830
|
+
/**
|
|
2831
|
+
* Alias for `rightTrigger` (analog right trigger).
|
|
2832
|
+
* `r2` is what it's called on PlayStation controllers.
|
|
2833
|
+
*/
|
|
2834
|
+
get r2(): number;
|
|
2835
|
+
/**
|
|
2836
|
+
* Verbose alias for `lsb`.
|
|
2837
|
+
*/
|
|
2838
|
+
get leftStickButton(): number;
|
|
2839
|
+
/**
|
|
2840
|
+
* Verbose alias for `rsb`.
|
|
2841
|
+
*/
|
|
2842
|
+
get rightStickButton(): number;
|
|
2843
|
+
/**
|
|
2844
|
+
* Alias for `lsb` (left stick button).
|
|
2845
|
+
* `l3` is what it's called on PlayStation controllers.
|
|
2846
|
+
*/
|
|
2847
|
+
get l3(): number;
|
|
2848
|
+
/**
|
|
2849
|
+
* Alias for `rsb` (right stick button).
|
|
2850
|
+
* `r3` is what it's called on PlayStation controllers.
|
|
2851
|
+
*/
|
|
2852
|
+
get r3(): number;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
class _Contros extends Array<Contro> {
|
|
2856
|
+
/**
|
|
2857
|
+
* Used internally to create the `contros` array (aka `controllers`)
|
|
2858
|
+
* of `Contro` objects, which store the input status of buttons,
|
|
2859
|
+
* triggers, and sticks on game controllers.
|
|
2860
|
+
*/
|
|
2861
|
+
constructor();
|
|
2862
|
+
/**
|
|
2863
|
+
* Swap controller positions in this controllers array.
|
|
2864
|
+
* @param indexA
|
|
2865
|
+
* @param indexB
|
|
2866
|
+
*/
|
|
2867
|
+
swap(indexA: number, indexB: number): void;
|
|
2868
|
+
/**
|
|
2869
|
+
* Removes a controller from this controllers array
|
|
2870
|
+
* by setting `contros[index] = null`.
|
|
2871
|
+
*
|
|
2872
|
+
* Newly connected controllers fill the first empty slot.
|
|
2873
|
+
* @param index
|
|
2874
|
+
*/
|
|
2875
|
+
remove(index: number): void;
|
|
2876
|
+
/**
|
|
2877
|
+
* Runs when a controller is connected. By default it
|
|
2878
|
+
* always returns true. Overwrite this function to customize
|
|
2879
|
+
* the behavior.
|
|
2880
|
+
*
|
|
2881
|
+
* For example, it could be customized to filter
|
|
2882
|
+
* controllers based on their model info.
|
|
2883
|
+
*
|
|
2884
|
+
* Doesn't run if a controller in the `controllers` array
|
|
2885
|
+
* is reconnected.
|
|
2886
|
+
* @param gamepad
|
|
2887
|
+
* @returns true if the controller should be added to this q5play controllers array
|
|
2888
|
+
*/
|
|
2889
|
+
onConnect(gamepad: Gamepad): boolean;
|
|
2890
|
+
/**
|
|
2891
|
+
* Runs when a controller is disconnected. by default it
|
|
2892
|
+
* always returns false. Overwrite this function to customize
|
|
2893
|
+
* the behavior.
|
|
2894
|
+
*
|
|
2895
|
+
* Removing a controller from the `controllers` array
|
|
2896
|
+
* usually is not desirable, because the controller could be
|
|
2897
|
+
* reconnected later. By default, the controller is kept in
|
|
2898
|
+
* the array and its state is reset.
|
|
2899
|
+
* @param gamepad
|
|
2900
|
+
* @returns true if the controllers should be removed from this q5play controllers array
|
|
2901
|
+
*/
|
|
2902
|
+
onDisconnect(gamepad: Gamepad): boolean;
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
function colorPal(c: string, palette: number | any): string;
|
|
2906
|
+
function EmojiImage(emoji: string, textSize: number): Q5.Image;
|
|
2907
|
+
function spriteArt(txt: string, scale: number, palette: number | any): Q5.Image;
|
|
2908
|
+
function animation(ani: Ani, x: number, y: number, r: number, sX: number, sY: number): void;
|
|
2909
|
+
function delay(milliseconds: number): Promise<any>;
|
|
2910
|
+
|
|
2911
|
+
let allSprites: Group;
|
|
2912
|
+
let world: World;
|
|
2913
|
+
let camera: Camera;
|
|
2914
|
+
let mouse: _Mouse;
|
|
2915
|
+
let pointers: _Pointer[];
|
|
2916
|
+
let pointer: _Pointer;
|
|
2917
|
+
let kb: _Keyboard;
|
|
2918
|
+
let keyboard: _Keyboard;
|
|
2919
|
+
let contros: _Contros;
|
|
2920
|
+
let controllers: _Contros;
|
|
2921
|
+
let contro: Contro;
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
export {};
|