angry-pixel 1.2.17 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -86
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2218 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -8
- package/package.dev.json +0 -32
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,2218 @@
|
|
|
1
|
-
|
|
1
|
+
type DependencyType = {
|
|
2
|
+
new (...args: any[]): any;
|
|
3
|
+
};
|
|
4
|
+
type DependencyName = string | symbol;
|
|
5
|
+
type PropertyKey = string | symbol;
|
|
6
|
+
declare class Container {
|
|
7
|
+
private instances;
|
|
8
|
+
private types;
|
|
9
|
+
add(type: DependencyType, name?: DependencyName): Container;
|
|
10
|
+
set(name: DependencyName, dependency: any): Container;
|
|
11
|
+
get<T>(name: DependencyName): T;
|
|
12
|
+
has(name: DependencyName): boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function injectable(name: DependencyName): (target: DependencyType) => void;
|
|
15
|
+
declare function inject(name: DependencyName): (target: any, propertyKey: PropertyKey, parameterIndex?: number) => void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Represents a 2D vector and provides static methods for vector calculations.
|
|
19
|
+
* @category Math
|
|
20
|
+
* @public
|
|
21
|
+
* @example
|
|
22
|
+
* ```js
|
|
23
|
+
* const v1 = new Vector2(2, 1);
|
|
24
|
+
* const v2 = new Vector2(3, 2);
|
|
25
|
+
* const v3 = new Vector2(); // zero vector
|
|
26
|
+
*
|
|
27
|
+
* Vector2.add(v3, v1, v2);
|
|
28
|
+
* v3.x // 5
|
|
29
|
+
* v3.y // 3
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare class Vector2 {
|
|
33
|
+
private _x;
|
|
34
|
+
private _y;
|
|
35
|
+
private _direction;
|
|
36
|
+
constructor(x?: number, y?: number);
|
|
37
|
+
get x(): number;
|
|
38
|
+
set x(x: number);
|
|
39
|
+
get y(): number;
|
|
40
|
+
set y(y: number);
|
|
41
|
+
/**
|
|
42
|
+
* Get the magnitude of the vector
|
|
43
|
+
*
|
|
44
|
+
* @returns The magnitude of the vector
|
|
45
|
+
*/
|
|
46
|
+
get magnitude(): number;
|
|
47
|
+
/**
|
|
48
|
+
* Get the direction as an unit vector
|
|
49
|
+
*
|
|
50
|
+
* @returns The direction vector
|
|
51
|
+
*/
|
|
52
|
+
get direction(): Vector2;
|
|
53
|
+
/**
|
|
54
|
+
* Set the vector
|
|
55
|
+
*
|
|
56
|
+
* @param x The x value
|
|
57
|
+
* @param y The y value
|
|
58
|
+
*/
|
|
59
|
+
set(x: number, y: number): void;
|
|
60
|
+
/**
|
|
61
|
+
* Copy the target vector properties
|
|
62
|
+
*
|
|
63
|
+
* @param vector The vector to copy from
|
|
64
|
+
*/
|
|
65
|
+
copy(vector: Vector2): void;
|
|
66
|
+
/**
|
|
67
|
+
* Compare if two vector are equals
|
|
68
|
+
*
|
|
69
|
+
* @param vector The vector to compare
|
|
70
|
+
* @returns True if the vectors are equals, false if not
|
|
71
|
+
*/
|
|
72
|
+
equals(vector: Vector2): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Colne a vector into a new instace
|
|
75
|
+
*
|
|
76
|
+
* @returns The cloned vector
|
|
77
|
+
*/
|
|
78
|
+
clone(): Vector2;
|
|
79
|
+
/**
|
|
80
|
+
* Get the distance with another vector
|
|
81
|
+
*
|
|
82
|
+
* @param vector The vector to compare
|
|
83
|
+
* @returns The magnitude of the distance
|
|
84
|
+
*/
|
|
85
|
+
distance(vector: Vector2): number;
|
|
86
|
+
/**
|
|
87
|
+
* Calculates a + b
|
|
88
|
+
* @param out The output vector
|
|
89
|
+
* @param a The first operand
|
|
90
|
+
* @param b The second operand
|
|
91
|
+
* @returns The output vector
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* const v1 = new Vector2(2, 1);
|
|
95
|
+
* const v2 = new Vector2(3, 2);
|
|
96
|
+
* const v3 = Vector2.add(new Vector2(), v1, v2);
|
|
97
|
+
* v3.x // 5
|
|
98
|
+
* v3.y // 3
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
static add(out: Vector2, a: Vector2, b: Vector2): Vector2;
|
|
102
|
+
/**
|
|
103
|
+
* Calculates a - b
|
|
104
|
+
*
|
|
105
|
+
* @param out The output vector
|
|
106
|
+
* @param a The first operand
|
|
107
|
+
* @param b The second operand
|
|
108
|
+
* @returns The output vector
|
|
109
|
+
* @example
|
|
110
|
+
* ```js
|
|
111
|
+
* const v1 = new Vector2(3, 2);
|
|
112
|
+
* const v2 = new Vector2(2, 1);
|
|
113
|
+
* const v3 = Vector2.subtract(new Vector2(), v1, v2);
|
|
114
|
+
* v3.x // 1
|
|
115
|
+
* v3.y // 1
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
static subtract(out: Vector2, a: Vector2, b: Vector2): Vector2;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the unit vector
|
|
121
|
+
*
|
|
122
|
+
* @param out The output vector
|
|
123
|
+
* @param a The vector to get the unit
|
|
124
|
+
* @returns The output vector
|
|
125
|
+
* @example
|
|
126
|
+
* ```js
|
|
127
|
+
* const v1 = new Vector2(3, 0);
|
|
128
|
+
* const v2 = Vector2.unit(new Vector2(), v1);
|
|
129
|
+
* v2.x // 1
|
|
130
|
+
* v2.y // 0
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
static unit(out: Vector2, a: Vector2): Vector2;
|
|
134
|
+
/**
|
|
135
|
+
* Normalize a vector
|
|
136
|
+
*
|
|
137
|
+
* @param out The output vector
|
|
138
|
+
* @param a The vector to normalize
|
|
139
|
+
* @returns The output vector
|
|
140
|
+
* @example
|
|
141
|
+
* ```js
|
|
142
|
+
* const v1 = new Vector2(0, 2);
|
|
143
|
+
* const v2 = Vector2.normal(new Vector2(), v1);
|
|
144
|
+
* v2.x // -2
|
|
145
|
+
* v2.y // 0
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
static normal(out: Vector2, a: Vector2): Vector2;
|
|
149
|
+
/**
|
|
150
|
+
* Scale a vector
|
|
151
|
+
*
|
|
152
|
+
* @param out The output vector
|
|
153
|
+
* @param a The vector to scale
|
|
154
|
+
* @param scalar The scalar value
|
|
155
|
+
* @returns The output vector
|
|
156
|
+
* @example
|
|
157
|
+
* ```js
|
|
158
|
+
* const v1 = new Vector2(3, 2);
|
|
159
|
+
* const v2 = Vector2.scale(new Vector2(), v1, 2);
|
|
160
|
+
* v2.x // 6
|
|
161
|
+
* v2.y // 4
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
static scale(out: Vector2, a: Vector2, scalar: number): Vector2;
|
|
165
|
+
/**
|
|
166
|
+
* Calculates the dot product of two vectors and returns a scalar value
|
|
167
|
+
*
|
|
168
|
+
* @param a The first operand
|
|
169
|
+
* @param b The second operand
|
|
170
|
+
* @returns The dot product result
|
|
171
|
+
* @example
|
|
172
|
+
* ```js
|
|
173
|
+
* const v1 = new Vector2(3, 2);
|
|
174
|
+
* const v2 = new Vector2(2, 1);
|
|
175
|
+
* Vector2.dot(v1, v2); // 8
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
static dot(a: Vector2, b: Vector2): number;
|
|
179
|
+
/**
|
|
180
|
+
* Calculates the cross product of two vectors and returns a scalar value
|
|
181
|
+
*
|
|
182
|
+
* @param a The first operand
|
|
183
|
+
* @param b The second operand
|
|
184
|
+
* @returns The cross produc result
|
|
185
|
+
* @example
|
|
186
|
+
* ```js
|
|
187
|
+
* const v1 = new Vector2(3, 2);
|
|
188
|
+
* const v2 = new Vector2(2, 1);
|
|
189
|
+
* Vector2.cross(v1, v2); // -1
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
static cross(a: Vector2, b: Vector2): number;
|
|
193
|
+
/**
|
|
194
|
+
* Rounds a vector
|
|
195
|
+
*
|
|
196
|
+
* @param a The vector to round
|
|
197
|
+
* @returns The output vector
|
|
198
|
+
* @example
|
|
199
|
+
* ```js
|
|
200
|
+
* const v1 = new Vector2(3.9, 2.2);
|
|
201
|
+
* const v2 = Vector2.round(new Vector2(), v1);
|
|
202
|
+
* v2.x // 4
|
|
203
|
+
* v2.y // 2
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
static round(out: Vector2, a: Vector2): Vector2;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Represents an axis aligned rectangle
|
|
211
|
+
* @category Math
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
declare class Rectangle {
|
|
215
|
+
width: number;
|
|
216
|
+
height: number;
|
|
217
|
+
private _position;
|
|
218
|
+
private _center;
|
|
219
|
+
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
220
|
+
get x(): number;
|
|
221
|
+
set x(value: number);
|
|
222
|
+
get y(): number;
|
|
223
|
+
set y(value: number);
|
|
224
|
+
get x1(): number;
|
|
225
|
+
get y1(): number;
|
|
226
|
+
get position(): Vector2;
|
|
227
|
+
set position(position: Vector2);
|
|
228
|
+
get center(): Vector2;
|
|
229
|
+
/**
|
|
230
|
+
* Set the rectangle
|
|
231
|
+
*
|
|
232
|
+
* @param x
|
|
233
|
+
* @param y
|
|
234
|
+
* @param width
|
|
235
|
+
* @param height
|
|
236
|
+
*/
|
|
237
|
+
set(x: number, y: number, width: number, height: number): void;
|
|
238
|
+
/**
|
|
239
|
+
* Compare if two rectangles are equals
|
|
240
|
+
*
|
|
241
|
+
* @param rectangle The rectangle to compare
|
|
242
|
+
* @returns TRUE if the rectangles are equals, FALSE if not
|
|
243
|
+
*/
|
|
244
|
+
equals(rectangle: Rectangle): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Copy the target rectangle properties
|
|
247
|
+
*
|
|
248
|
+
* @param rect The rectangle to copy from
|
|
249
|
+
*/
|
|
250
|
+
copy(rect: Rectangle): void;
|
|
251
|
+
/**
|
|
252
|
+
* Check if the target rectangle is overlapping
|
|
253
|
+
*
|
|
254
|
+
* @param rect The target rectangle
|
|
255
|
+
* @returns TRUE or FALSE
|
|
256
|
+
*/
|
|
257
|
+
overlaps(rect: Rectangle): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Check if the target rectangle is contained
|
|
260
|
+
*
|
|
261
|
+
* @param rect The target rectangle
|
|
262
|
+
* @returns TRUE or FALSE
|
|
263
|
+
*/
|
|
264
|
+
contains(rect: Rectangle): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Check if the target vector is contained
|
|
267
|
+
*
|
|
268
|
+
* @param vector The target vector
|
|
269
|
+
* @returns TRUE or FALSE
|
|
270
|
+
*/
|
|
271
|
+
contains(vector: Vector2): boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Clamps the given value between the given minimum and maximum values.
|
|
276
|
+
* @category Math
|
|
277
|
+
* @public
|
|
278
|
+
* @param value number to clamp
|
|
279
|
+
* @param min min value
|
|
280
|
+
* @param max max value
|
|
281
|
+
* @returns clamped value
|
|
282
|
+
*/
|
|
283
|
+
declare const clamp: (value: number, min: number, max: number) => number;
|
|
284
|
+
/**
|
|
285
|
+
* Returns a random integer number between the given minimum and maximum values.
|
|
286
|
+
* @category Math
|
|
287
|
+
* @public
|
|
288
|
+
* @param min min value
|
|
289
|
+
* @param max max value
|
|
290
|
+
* @returns the random int value
|
|
291
|
+
*/
|
|
292
|
+
declare const randomInt: (min: number, max: number) => number;
|
|
293
|
+
/**
|
|
294
|
+
* Returns a random float number between the given minimum and maximum values.
|
|
295
|
+
* @category Math
|
|
296
|
+
* @public
|
|
297
|
+
* @param min min value
|
|
298
|
+
* @param max max value
|
|
299
|
+
* @returns the random float value
|
|
300
|
+
*/
|
|
301
|
+
declare const randomFloat: (min: number, max: number, decimals?: number) => number;
|
|
302
|
+
/**
|
|
303
|
+
* Corrects a floating number to a given number of decimal places.
|
|
304
|
+
* @category Math
|
|
305
|
+
* @public
|
|
306
|
+
* @param value the value to round
|
|
307
|
+
* @param decimals the number of decimals
|
|
308
|
+
* @returns the rounded value
|
|
309
|
+
*/
|
|
310
|
+
declare const fixedRound: (value: number, decimals: number) => number;
|
|
311
|
+
/**
|
|
312
|
+
* Generate an array with a range of numbers.
|
|
313
|
+
* @category Math
|
|
314
|
+
* @public
|
|
315
|
+
* @param start the starting value
|
|
316
|
+
* @param end the end value
|
|
317
|
+
* @param steps the steps to move
|
|
318
|
+
* @returns number range
|
|
319
|
+
*/
|
|
320
|
+
declare const range: (start: number, end: number, steps?: number) => number[];
|
|
321
|
+
/**
|
|
322
|
+
* Evaluates whether the given value is between the minimum and the maximum (both inclusive).
|
|
323
|
+
* @category Math
|
|
324
|
+
* @public
|
|
325
|
+
* @param value number to compare
|
|
326
|
+
* @param min min value
|
|
327
|
+
* @param max max value
|
|
328
|
+
* @returns true if the number is between the min and the max, false instead
|
|
329
|
+
*/
|
|
330
|
+
declare const between: (value: number, min: number, max: number) => boolean;
|
|
331
|
+
|
|
332
|
+
interface Shape {
|
|
333
|
+
boundingBox: Rectangle;
|
|
334
|
+
collider: number;
|
|
335
|
+
entity: number;
|
|
336
|
+
id: number;
|
|
337
|
+
ignoreCollisionsWithLayers: string[];
|
|
338
|
+
layer: string;
|
|
339
|
+
position: Vector2;
|
|
340
|
+
projectionAxes: Vector2[];
|
|
341
|
+
radius: number;
|
|
342
|
+
rotation: number;
|
|
343
|
+
vertexModel: Vector2[];
|
|
344
|
+
vertices: Vector2[];
|
|
345
|
+
updateCollisions: boolean;
|
|
346
|
+
}
|
|
347
|
+
declare class Polygon implements Shape {
|
|
348
|
+
rotation: number;
|
|
349
|
+
boundingBox: Rectangle;
|
|
350
|
+
collider: number;
|
|
351
|
+
entity: number;
|
|
352
|
+
id: number;
|
|
353
|
+
ignoreCollisionsWithLayers: string[];
|
|
354
|
+
layer: string;
|
|
355
|
+
position: Vector2;
|
|
356
|
+
projectionAxes: Vector2[];
|
|
357
|
+
radius: number;
|
|
358
|
+
vertices: Vector2[];
|
|
359
|
+
updateCollisions: boolean;
|
|
360
|
+
private _vertexModel;
|
|
361
|
+
get vertexModel(): Vector2[];
|
|
362
|
+
set vertexModel(vertexModel: Vector2[]);
|
|
363
|
+
constructor(vertexModel: Vector2[], rotation?: number);
|
|
364
|
+
}
|
|
365
|
+
declare class Circumference implements Shape {
|
|
366
|
+
radius: number;
|
|
367
|
+
boundingBox: Rectangle;
|
|
368
|
+
collider: number;
|
|
369
|
+
entity: number;
|
|
370
|
+
id: number;
|
|
371
|
+
ignoreCollisionsWithLayers: string[];
|
|
372
|
+
layer: string;
|
|
373
|
+
position: Vector2;
|
|
374
|
+
projectionAxes: Vector2[];
|
|
375
|
+
rotation: number;
|
|
376
|
+
vertexModel: Vector2[];
|
|
377
|
+
vertices: Vector2[];
|
|
378
|
+
updateCollisions: boolean;
|
|
379
|
+
constructor(radius: number);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Broad phase collision methods
|
|
384
|
+
* - QuadTree: Stores the shapes in an incremental quad tree.
|
|
385
|
+
* - SpartialGrid: Stores the shapes in an incremental spartial grid.
|
|
386
|
+
* @category Config
|
|
387
|
+
* @public
|
|
388
|
+
*/
|
|
389
|
+
declare enum BroadPhaseMethods {
|
|
390
|
+
QuadTree = 0,
|
|
391
|
+
SpartialGrid = 1
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
interface CollisionResolution {
|
|
395
|
+
penetration: number;
|
|
396
|
+
direction: Vector2;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Resolution phase collision methods
|
|
401
|
+
* - AABB (axis-aligned bounding box): It only works with axis-aligned rectangles and lines and cimcurferences.
|
|
402
|
+
* - SAT (Separation axis theorem): It works with every type of shape.
|
|
403
|
+
* @category Config
|
|
404
|
+
* @public
|
|
405
|
+
*/
|
|
406
|
+
declare enum CollisionMethods {
|
|
407
|
+
AABB = 0,
|
|
408
|
+
SAT = 1
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
interface Collider {
|
|
412
|
+
ignoreCollisionsWithLayers: string[];
|
|
413
|
+
layer: string;
|
|
414
|
+
offset: Vector2;
|
|
415
|
+
physics: boolean;
|
|
416
|
+
shapes: Shape[];
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type Entity = number;
|
|
420
|
+
type Component = {
|
|
421
|
+
[key: string]: any;
|
|
422
|
+
};
|
|
423
|
+
type ComponentType<T extends Component = Component> = {
|
|
424
|
+
new (...args: any[]): T;
|
|
425
|
+
};
|
|
426
|
+
type SearchResult<T extends Component> = {
|
|
427
|
+
entity: Entity;
|
|
428
|
+
component: T;
|
|
429
|
+
};
|
|
430
|
+
type SearchCriteria = {
|
|
431
|
+
[key: string]: any;
|
|
432
|
+
};
|
|
433
|
+
declare class EntityManager {
|
|
434
|
+
private lastEntityId;
|
|
435
|
+
private lastComponentTypeId;
|
|
436
|
+
private components;
|
|
437
|
+
private disabledEntities;
|
|
438
|
+
private disabledComponents;
|
|
439
|
+
createEntity(): Entity;
|
|
440
|
+
createEntity(components: Array<ComponentType | Component>): Entity;
|
|
441
|
+
removeEntity(entity: Entity): void;
|
|
442
|
+
removeAllEntities(): void;
|
|
443
|
+
isEntityEnabled(entity: Entity): boolean;
|
|
444
|
+
enableEntity(entity: Entity): void;
|
|
445
|
+
disableEntity(entity: Entity): void;
|
|
446
|
+
disableEntitiesByComponent(componentType: ComponentType): void;
|
|
447
|
+
enableEntitiesByComponent(componentType: ComponentType): void;
|
|
448
|
+
addComponent<T extends Component>(entity: Entity, componentType: ComponentType<T>): T;
|
|
449
|
+
addComponent<T extends Component>(entity: Entity, component: T): T;
|
|
450
|
+
hasComponent(entity: Entity, componentType: ComponentType): boolean;
|
|
451
|
+
getComponent<T extends Component>(entity: Entity, componentType: ComponentType<T>): T;
|
|
452
|
+
getComponents(entity: Entity): Component[];
|
|
453
|
+
getEntityForComponent(component: Component): Entity;
|
|
454
|
+
removeComponent(component: Component): void;
|
|
455
|
+
removeComponent(entity: Entity, componentType: ComponentType): void;
|
|
456
|
+
isComponentEnabled(component: Component): boolean;
|
|
457
|
+
isComponentEnabled<T extends Component>(entity: Entity, componentType: ComponentType<T>): boolean;
|
|
458
|
+
disableComponent(component: Component): void;
|
|
459
|
+
disableComponent<T extends Component>(entity: Entity, componentType: ComponentType<T>): void;
|
|
460
|
+
enableComponent(component: Component): void;
|
|
461
|
+
enableComponent<T extends Component>(entity: Entity, componentType: ComponentType<T>): void;
|
|
462
|
+
search<T extends Component>(componentType: ComponentType<T>, criteria?: SearchCriteria, includeDisabled?: boolean): SearchResult<T>[];
|
|
463
|
+
searchEntitiesByComponents(componentTypes: ComponentType[]): Entity[];
|
|
464
|
+
private getComponentTypeId;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
interface System {
|
|
468
|
+
onCreate?(): void;
|
|
469
|
+
onDestroy?(): void;
|
|
470
|
+
onDisabled?(): void;
|
|
471
|
+
onEnabled?(): void;
|
|
472
|
+
onUpdate(): void;
|
|
473
|
+
}
|
|
474
|
+
type SystemType<T extends System = System> = {
|
|
475
|
+
new (...args: any[]): T;
|
|
476
|
+
};
|
|
477
|
+
type SystemGroup = string | number | symbol;
|
|
478
|
+
declare class SystemManager {
|
|
479
|
+
private systems;
|
|
480
|
+
private findSystemIndex;
|
|
481
|
+
addSystem(system: System, group: SystemGroup): void;
|
|
482
|
+
hasSystem(systemType: SystemType): boolean;
|
|
483
|
+
getSystem<T extends System>(systemType: SystemType<T>): T;
|
|
484
|
+
enableSystem(systemType: SystemType): void;
|
|
485
|
+
disableSystem(systemType: SystemType): void;
|
|
486
|
+
setExecutionOrder(systemType: SystemType, position: number): void;
|
|
487
|
+
removeSystem(systemType: SystemType): void;
|
|
488
|
+
update(group: SystemGroup): void;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Represent a collision. It contains the colliders involved and the resolution data.
|
|
493
|
+
* @category Components
|
|
494
|
+
* @public
|
|
495
|
+
*/
|
|
496
|
+
interface Collision {
|
|
497
|
+
localCollider: Collider;
|
|
498
|
+
localEntity: Entity;
|
|
499
|
+
remoteCollider: Collider;
|
|
500
|
+
remoteEntity: Entity;
|
|
501
|
+
resolution: CollisionResolution;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
declare class CollisionRepository {
|
|
505
|
+
private collisions;
|
|
506
|
+
findCollisionsForCollider(collider: Collider): Collision[];
|
|
507
|
+
findCollisionsForColliderAndLayer(collider: Collider, layer: string): Collision[];
|
|
508
|
+
findAll(): Collision[];
|
|
509
|
+
persist(collision: Collision): void;
|
|
510
|
+
removeAll(): void;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Array containing which layers will collide with each other.
|
|
515
|
+
* @category Config
|
|
516
|
+
* @public
|
|
517
|
+
*/
|
|
518
|
+
type CollisionMatrix = [string, string][];
|
|
519
|
+
|
|
520
|
+
interface GameConfig {
|
|
521
|
+
/** HTML element where the game will be created */
|
|
522
|
+
containerNode: HTMLElement;
|
|
523
|
+
/** Game width */
|
|
524
|
+
width: number;
|
|
525
|
+
/** Game height */
|
|
526
|
+
height: number;
|
|
527
|
+
/** Enables the debug mode */
|
|
528
|
+
debugEnabled?: boolean;
|
|
529
|
+
/** Background color of canvas */
|
|
530
|
+
canvasColor?: string;
|
|
531
|
+
/** Framerate for physics execution. The allowed values are 60, 120, 180, 240.
|
|
532
|
+
* The higher the framerate, the more accurate the physics will be, but it will consume more processor resources.
|
|
533
|
+
* Default value is 180.
|
|
534
|
+
*/
|
|
535
|
+
physicsFramerate?: number;
|
|
536
|
+
/** Enable Headless mode. The input and rendering functions are turned off. Ideal for game server development */
|
|
537
|
+
headless?: boolean;
|
|
538
|
+
/** Collision configuration options */
|
|
539
|
+
collisions?: {
|
|
540
|
+
/** Collision detection method: CollisionMethods.SAT or CollisionMethods.ABB. Default value is CollisionMethods.SAT */
|
|
541
|
+
collisionMethod?: CollisionMethods;
|
|
542
|
+
/** Define a fixed rectangular area for collision detection */
|
|
543
|
+
collisionMatrix?: CollisionMatrix;
|
|
544
|
+
/** Collision broad phase method: BroadPhaseMethods.QuadTree or BroadPhaseMethods.SpartialGrid. Default values is BroadPhaseMethods.SpartialGrid */
|
|
545
|
+
collisionBroadPhaseMethod?: BroadPhaseMethods;
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
declare class SystemFactory {
|
|
550
|
+
private readonly container;
|
|
551
|
+
private readonly systemManager;
|
|
552
|
+
private lastSystemTypeId;
|
|
553
|
+
constructor(container: Container, systemManager: SystemManager);
|
|
554
|
+
createSystemIfNotExists(systemType: SystemType): void;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Manages the asset loading (images, fonts, audios, videos).
|
|
559
|
+
* @public
|
|
560
|
+
* @category Managers
|
|
561
|
+
* @example
|
|
562
|
+
* ```js
|
|
563
|
+
* this.assetManager.loadImage("image.png");
|
|
564
|
+
* this.assetManager.loadAudio("audio.ogg");
|
|
565
|
+
* this.assetManager.loadVideo("video.mp4");
|
|
566
|
+
* this.assetManager.loadFont("custom-font", "custom-font.ttf");
|
|
567
|
+
*
|
|
568
|
+
* const imageElement = this.assetManager.getImage("image.png");
|
|
569
|
+
* const audioElement = this.assetManager.getAudio("audio.ogg");
|
|
570
|
+
* const videoElement = this.assetManager.getVideo("video.mp4");
|
|
571
|
+
* const fontFace = this.assetManager.getFont("custom-font");
|
|
572
|
+
*
|
|
573
|
+
* if (this.assetManager.getAssetsLoaded()) {
|
|
574
|
+
* // do something when assets are loaded
|
|
575
|
+
* }
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
declare class AssetManager {
|
|
579
|
+
private readonly assets;
|
|
580
|
+
/**
|
|
581
|
+
* Returns TRUE if the assets are loaded
|
|
582
|
+
* @returns TRUE or FALSE
|
|
583
|
+
*/
|
|
584
|
+
getAssetsLoaded(): boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Loads an image asset
|
|
587
|
+
* @param url The asset URL
|
|
588
|
+
* @param preloadTexture Creates the texture to be rendered at load time [optional]
|
|
589
|
+
* @returns The HTML Image element created
|
|
590
|
+
*/
|
|
591
|
+
loadImage(url: string): HTMLImageElement;
|
|
592
|
+
/**
|
|
593
|
+
* Loads an audio asset
|
|
594
|
+
* @param url The asset URL
|
|
595
|
+
* @returns The HTML Audio element created
|
|
596
|
+
*/
|
|
597
|
+
loadAudio(url: string): HTMLAudioElement;
|
|
598
|
+
/**
|
|
599
|
+
* Loads a font asset
|
|
600
|
+
* @param family The font family name
|
|
601
|
+
* @param url The asset URL
|
|
602
|
+
* @returns The FontFace object created
|
|
603
|
+
*/
|
|
604
|
+
loadFont(family: string, url: string): FontFace;
|
|
605
|
+
/**
|
|
606
|
+
* Loads an video asset
|
|
607
|
+
* @param url The asset URL
|
|
608
|
+
* @returns The HTML Video element created
|
|
609
|
+
*/
|
|
610
|
+
loadVideo(url: string): HTMLVideoElement;
|
|
611
|
+
/**
|
|
612
|
+
* Retrieves an image asset
|
|
613
|
+
* @param url The asset URL
|
|
614
|
+
* @returns The HTML Image element
|
|
615
|
+
*/
|
|
616
|
+
getImage(url: string): HTMLImageElement;
|
|
617
|
+
/**
|
|
618
|
+
* Retrieves an audio asset
|
|
619
|
+
* @param url The asset URL
|
|
620
|
+
* @returns The HTML Audio element
|
|
621
|
+
*/
|
|
622
|
+
getAudio(url: string): HTMLAudioElement;
|
|
623
|
+
/**
|
|
624
|
+
* Retrieves a font asset
|
|
625
|
+
* @param family The font family name
|
|
626
|
+
* @returns The Font element
|
|
627
|
+
*/
|
|
628
|
+
getFont(family: string): FontFace;
|
|
629
|
+
/**
|
|
630
|
+
* Retrieves a video asset
|
|
631
|
+
* @param url The asset URL
|
|
632
|
+
* @returns The HTML Video element
|
|
633
|
+
*/
|
|
634
|
+
getVideo(url: string): HTMLVideoElement;
|
|
635
|
+
private createAsset;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
type SceneType<T extends Scene = Scene> = {
|
|
639
|
+
new (entityManager: EntityManager, assetManager: AssetManager): T;
|
|
640
|
+
};
|
|
641
|
+
declare abstract class Scene {
|
|
642
|
+
protected readonly entityManager: EntityManager;
|
|
643
|
+
protected readonly assetManager: AssetManager;
|
|
644
|
+
systems: SystemType[];
|
|
645
|
+
constructor(entityManager: EntityManager, assetManager: AssetManager);
|
|
646
|
+
loadAssets(): void;
|
|
647
|
+
setup(): void;
|
|
648
|
+
}
|
|
649
|
+
declare class SceneManager {
|
|
650
|
+
private readonly systemManager;
|
|
651
|
+
private readonly systemFactory;
|
|
652
|
+
private readonly entityManager;
|
|
653
|
+
private readonly assetManager;
|
|
654
|
+
private readonly scenes;
|
|
655
|
+
private openingSceneName;
|
|
656
|
+
private currentSceneName;
|
|
657
|
+
private sceneNameToBeLoaded;
|
|
658
|
+
private loadingScene;
|
|
659
|
+
constructor(systemManager: SystemManager, systemFactory: SystemFactory, entityManager: EntityManager, assetManager: AssetManager);
|
|
660
|
+
addScene(sceneType: SceneType, name: string, openingScene?: boolean): void;
|
|
661
|
+
loadScene(name: string): void;
|
|
662
|
+
loadOpeningScene(): void;
|
|
663
|
+
/** @internal */
|
|
664
|
+
update(): void;
|
|
665
|
+
private destroyCurrentScene;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Game is the main class that contains all the managers, scenes, entities and components. It allows to start and stop the execution of the game.
|
|
670
|
+
* @public
|
|
671
|
+
* @category Core
|
|
672
|
+
* @example
|
|
673
|
+
* ```js
|
|
674
|
+
* const game = new Game({
|
|
675
|
+
* containerNode: document.getElementById("app"),
|
|
676
|
+
* width: 1920,
|
|
677
|
+
* height: 1080,
|
|
678
|
+
* });
|
|
679
|
+
* game.addScene(MainScene, "MainScene");
|
|
680
|
+
* game.start();
|
|
681
|
+
* ```
|
|
682
|
+
* @example
|
|
683
|
+
* ```js
|
|
684
|
+
* const game = new Game({
|
|
685
|
+
* containerNode: document.getElementById("app"),
|
|
686
|
+
* width: 1920,
|
|
687
|
+
* height: 1080,
|
|
688
|
+
* debugEnabled: false,
|
|
689
|
+
* canvasColor: "#000000",
|
|
690
|
+
* physicsFramerate: 180,
|
|
691
|
+
* collisions: {
|
|
692
|
+
* collisionMatrix: [
|
|
693
|
+
* ["layer1", "layer2"],
|
|
694
|
+
* ["layer1", "layer3"],
|
|
695
|
+
* ],
|
|
696
|
+
* collisionMethod: CollisionMethods.SAT,
|
|
697
|
+
* collisionBroadPhaseMethod: BroadPhaseMethods.SpartialGrid,
|
|
698
|
+
* }
|
|
699
|
+
* });
|
|
700
|
+
* game.addScene(MainScene, "MainScene");
|
|
701
|
+
* game.start();
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
declare class Game {
|
|
705
|
+
private readonly container;
|
|
706
|
+
constructor(gameConfig: GameConfig);
|
|
707
|
+
/**
|
|
708
|
+
* TRUE if the game is running
|
|
709
|
+
*/
|
|
710
|
+
get running(): boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Add a scene to the game
|
|
713
|
+
*
|
|
714
|
+
* @param sceneType The class of the scene
|
|
715
|
+
* @param name The name for the scene
|
|
716
|
+
* @param openingScene If this is the opening scene, set TRUE, FALSE instead (optional: default FALSE)
|
|
717
|
+
*/
|
|
718
|
+
addScene(sceneType: SceneType, name: string, openingScene?: boolean): void;
|
|
719
|
+
/**
|
|
720
|
+
* Add a new class to be used as dependency
|
|
721
|
+
*
|
|
722
|
+
* @param dependencyType The class of the dependency
|
|
723
|
+
* @param name The name for the dependecy (optional: if the class uses the "injectable" decorator, this parameter is unnecesary)
|
|
724
|
+
*/
|
|
725
|
+
addDependencyType(dependencyType: DependencyType, name?: DependencyName): void;
|
|
726
|
+
/**
|
|
727
|
+
* Add a new instance to be used as dependency
|
|
728
|
+
*
|
|
729
|
+
* @param dependency The dependency instance
|
|
730
|
+
* @param name The name for the dependecy
|
|
731
|
+
*/
|
|
732
|
+
addDependencyInstance(dependencyInstance: any, name: DependencyName): void;
|
|
733
|
+
/**
|
|
734
|
+
* Start the game
|
|
735
|
+
*/
|
|
736
|
+
start(): void;
|
|
737
|
+
/**
|
|
738
|
+
* Stop the game
|
|
739
|
+
*/
|
|
740
|
+
stop(): void;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** @category Components */
|
|
744
|
+
interface AnimatorOptions {
|
|
745
|
+
animations: Map<string, Animation>;
|
|
746
|
+
animation: string;
|
|
747
|
+
speed: number;
|
|
748
|
+
playing: boolean;
|
|
749
|
+
}
|
|
750
|
+
/** @category Components */
|
|
751
|
+
declare class Animator {
|
|
752
|
+
animations: Map<string, Animation>;
|
|
753
|
+
animation: string;
|
|
754
|
+
speed: number;
|
|
755
|
+
reset: boolean;
|
|
756
|
+
playing: boolean;
|
|
757
|
+
currentFrame: number;
|
|
758
|
+
currentTime: number;
|
|
759
|
+
/** @internal */
|
|
760
|
+
_currentAnimation: string;
|
|
761
|
+
constructor(options?: Partial<AnimatorOptions>);
|
|
762
|
+
}
|
|
763
|
+
/** @category Components */
|
|
764
|
+
declare class Animation {
|
|
765
|
+
image: HTMLImageElement | HTMLImageElement[];
|
|
766
|
+
slice: AnimationSlice;
|
|
767
|
+
frames: number[];
|
|
768
|
+
fps: number;
|
|
769
|
+
loop: boolean;
|
|
770
|
+
constructor(options?: Partial<Animation>);
|
|
771
|
+
}
|
|
772
|
+
/** @category Components */
|
|
773
|
+
type AnimationSlice = {
|
|
774
|
+
size: Vector2;
|
|
775
|
+
offset: Vector2;
|
|
776
|
+
padding: Vector2;
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
/** @category Components */
|
|
780
|
+
interface AudioPlayerOptions {
|
|
781
|
+
action: AudioPlayerAction;
|
|
782
|
+
audioSource: HTMLAudioElement;
|
|
783
|
+
loop: boolean;
|
|
784
|
+
volume: number;
|
|
785
|
+
}
|
|
786
|
+
/** @category Components */
|
|
787
|
+
declare class AudioPlayer {
|
|
788
|
+
action: AudioPlayerAction;
|
|
789
|
+
audioSource: HTMLAudioElement;
|
|
790
|
+
loop: boolean;
|
|
791
|
+
playing: boolean;
|
|
792
|
+
volume: number;
|
|
793
|
+
/** @internal */
|
|
794
|
+
_currentAudio: string;
|
|
795
|
+
constructor(options?: Partial<AudioPlayerOptions>);
|
|
796
|
+
}
|
|
797
|
+
type AudioPlayerAction = "stop" | "play" | "pause";
|
|
798
|
+
|
|
799
|
+
/** @category Components */
|
|
800
|
+
interface ButtonOptions {
|
|
801
|
+
shape: ButtonShape;
|
|
802
|
+
width: number;
|
|
803
|
+
height: number;
|
|
804
|
+
radius: number;
|
|
805
|
+
touchEnabled: boolean;
|
|
806
|
+
offset: Vector2;
|
|
807
|
+
onClick: () => void;
|
|
808
|
+
onPressed: () => void;
|
|
809
|
+
}
|
|
810
|
+
/** @category Components */
|
|
811
|
+
declare class Button {
|
|
812
|
+
/** The shape of the button */
|
|
813
|
+
shape: ButtonShape;
|
|
814
|
+
/** Width in pixels. Only for rectangle shaped buttons */
|
|
815
|
+
width: number;
|
|
816
|
+
/** Height in pixels. Only for rectangle shaped buttons */
|
|
817
|
+
height: number;
|
|
818
|
+
/** Radius in pixels. Only for circumference shaped buttons */
|
|
819
|
+
radius: number;
|
|
820
|
+
/** Enables interaction with touch screens */
|
|
821
|
+
touchEnabled: boolean;
|
|
822
|
+
/** X-axis and Y-axis offset */
|
|
823
|
+
offset: Vector2;
|
|
824
|
+
/** TRUE if it's pressed */
|
|
825
|
+
pressed: boolean;
|
|
826
|
+
/** Function executed when the button's click */
|
|
827
|
+
onClick: () => void;
|
|
828
|
+
/** Function executed when the button is pressed */
|
|
829
|
+
onPressed: () => void;
|
|
830
|
+
constructor(options?: Partial<ButtonOptions>);
|
|
831
|
+
}
|
|
832
|
+
/** @category Components */
|
|
833
|
+
declare enum ButtonShape {
|
|
834
|
+
Rectangle = 0,
|
|
835
|
+
Circumference = 1
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** @category Components */
|
|
839
|
+
declare class Children {
|
|
840
|
+
entities: Entity[];
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** @category Components */
|
|
844
|
+
declare class Parent {
|
|
845
|
+
entity: Entity;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/** @category Components */
|
|
849
|
+
interface TiledWrapperOptions {
|
|
850
|
+
tilemap: TiledTilemap;
|
|
851
|
+
layerToRender: string;
|
|
852
|
+
}
|
|
853
|
+
/** @category Components */
|
|
854
|
+
declare class TiledWrapper {
|
|
855
|
+
tilemap: TiledTilemap;
|
|
856
|
+
layerToRender: string;
|
|
857
|
+
constructor(options?: Partial<TiledWrapperOptions>);
|
|
858
|
+
}
|
|
859
|
+
/** @category Components */
|
|
860
|
+
interface TiledTilemap {
|
|
861
|
+
width: number;
|
|
862
|
+
height: number;
|
|
863
|
+
infinite: boolean;
|
|
864
|
+
layers: (TiledLayer | TiledObjectLayer)[];
|
|
865
|
+
renderorder: string;
|
|
866
|
+
tilesets: {
|
|
867
|
+
firstgid: number;
|
|
868
|
+
}[];
|
|
869
|
+
tilewidth: number;
|
|
870
|
+
tileheight: number;
|
|
871
|
+
properties?: TiledProperty[];
|
|
872
|
+
}
|
|
873
|
+
/** @category Components */
|
|
874
|
+
interface TiledChunk {
|
|
875
|
+
data: number[];
|
|
876
|
+
x: number;
|
|
877
|
+
y: number;
|
|
878
|
+
width: number;
|
|
879
|
+
height: number;
|
|
880
|
+
type?: string;
|
|
881
|
+
}
|
|
882
|
+
/** @category Components */
|
|
883
|
+
interface TiledLayer {
|
|
884
|
+
name: string;
|
|
885
|
+
id: number;
|
|
886
|
+
chunks?: TiledChunk[];
|
|
887
|
+
data?: number[];
|
|
888
|
+
x: number;
|
|
889
|
+
y: number;
|
|
890
|
+
type: "tilelayer";
|
|
891
|
+
width: number;
|
|
892
|
+
height: number;
|
|
893
|
+
opacity: number;
|
|
894
|
+
visible: boolean;
|
|
895
|
+
startx?: number;
|
|
896
|
+
starty?: number;
|
|
897
|
+
offsetx?: number;
|
|
898
|
+
offsety?: number;
|
|
899
|
+
tintcolor?: string;
|
|
900
|
+
properties?: TiledProperty[];
|
|
901
|
+
}
|
|
902
|
+
/** @category Components */
|
|
903
|
+
interface TiledObjectLayer {
|
|
904
|
+
draworder: string;
|
|
905
|
+
id: number;
|
|
906
|
+
name: string;
|
|
907
|
+
objects: TiledObject[];
|
|
908
|
+
opacity: number;
|
|
909
|
+
type: "objectgroup";
|
|
910
|
+
visible: true;
|
|
911
|
+
x: number;
|
|
912
|
+
y: number;
|
|
913
|
+
properties?: TiledProperty[];
|
|
914
|
+
}
|
|
915
|
+
/** @category Components */
|
|
916
|
+
interface TiledObject {
|
|
917
|
+
gid: number;
|
|
918
|
+
height: number;
|
|
919
|
+
id: number;
|
|
920
|
+
name: string;
|
|
921
|
+
rotation: number;
|
|
922
|
+
type: string;
|
|
923
|
+
visible: true;
|
|
924
|
+
width: number;
|
|
925
|
+
x: number;
|
|
926
|
+
y: number;
|
|
927
|
+
properties?: TiledProperty[];
|
|
928
|
+
}
|
|
929
|
+
/** @category Components */
|
|
930
|
+
interface TiledProperty {
|
|
931
|
+
name: string;
|
|
932
|
+
type: "int" | "bool" | "float" | "color" | "string";
|
|
933
|
+
value: number | string | boolean;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/** @category Components */
|
|
937
|
+
interface TransformOptions {
|
|
938
|
+
position: Vector2;
|
|
939
|
+
scale: Vector2;
|
|
940
|
+
rotation: number;
|
|
941
|
+
parent: Transform;
|
|
942
|
+
localPosition: Vector2;
|
|
943
|
+
localScale: Vector2;
|
|
944
|
+
localRotation: number;
|
|
945
|
+
}
|
|
946
|
+
/** @category Components */
|
|
947
|
+
declare class Transform {
|
|
948
|
+
/** Position relative to the zero point of the simulated world, or relative to the parent if it has one */
|
|
949
|
+
position: Vector2;
|
|
950
|
+
/** Scale on x-axis and y-axis */
|
|
951
|
+
scale: Vector2;
|
|
952
|
+
/** Rotation expressed in radians */
|
|
953
|
+
rotation: number;
|
|
954
|
+
/** The real position in the simulated world. It has the same value as `position` property if there is no parent */
|
|
955
|
+
localPosition: Vector2;
|
|
956
|
+
/** The real scale in the simulated world. It has the same value as `scale` property if there is no parent */
|
|
957
|
+
localScale: Vector2;
|
|
958
|
+
/** The real rotation in the simulated world. It has the same value as `rotation` property if there is no parent */
|
|
959
|
+
localRotation: number;
|
|
960
|
+
/** @internal */
|
|
961
|
+
_parentEntity: Entity;
|
|
962
|
+
/** @internal */
|
|
963
|
+
_childEntities: Entity[];
|
|
964
|
+
private _parent;
|
|
965
|
+
/** The parent transform. The position property became relative to this transform */
|
|
966
|
+
get parent(): Transform;
|
|
967
|
+
/** The parent transform. The position property became relative to this transform */
|
|
968
|
+
set parent(parent: Transform);
|
|
969
|
+
constructor(options?: Partial<TransformOptions>);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
interface BallColliderOptions {
|
|
973
|
+
/** Circumference radius */
|
|
974
|
+
radius: number;
|
|
975
|
+
/** X-Y axis offset */
|
|
976
|
+
offset: Vector2;
|
|
977
|
+
/** Collision layer*/
|
|
978
|
+
layer: string;
|
|
979
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
980
|
+
physics: boolean;
|
|
981
|
+
/** Ignores collisions with layers in the array */
|
|
982
|
+
ignoreCollisionsWithLayers: string[];
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Circumference shaped collider for 2d collisions.
|
|
986
|
+
* @public
|
|
987
|
+
* @category Components
|
|
988
|
+
*/
|
|
989
|
+
declare class BallCollider implements Collider {
|
|
990
|
+
/** Circumference radius */
|
|
991
|
+
radius: number;
|
|
992
|
+
/** X-Y axis offset */
|
|
993
|
+
offset: Vector2;
|
|
994
|
+
/** Collision layer*/
|
|
995
|
+
layer: string;
|
|
996
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
997
|
+
physics: boolean;
|
|
998
|
+
/** Ignores collisions with layers in the array */
|
|
999
|
+
ignoreCollisionsWithLayers: string[];
|
|
1000
|
+
/** @internal */
|
|
1001
|
+
shapes: Shape[];
|
|
1002
|
+
constructor(options?: Partial<BallColliderOptions>);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
interface BoxColliderOptions {
|
|
1006
|
+
/** Collision layer*/
|
|
1007
|
+
layer: string;
|
|
1008
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1009
|
+
physics: boolean;
|
|
1010
|
+
/** Width of the rectangle */
|
|
1011
|
+
width: number;
|
|
1012
|
+
/** Height of the rectangle */
|
|
1013
|
+
height: number;
|
|
1014
|
+
/** X-Y axis offset */
|
|
1015
|
+
offset: Vector2;
|
|
1016
|
+
/** Rectangle rotation in radians */
|
|
1017
|
+
rotation: number;
|
|
1018
|
+
/** Ignores collisions with layers in the array */
|
|
1019
|
+
ignoreCollisionsWithLayers: string[];
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Rectangle shaped collider for 2d collisions.
|
|
1023
|
+
* @public
|
|
1024
|
+
* @category Components
|
|
1025
|
+
*/
|
|
1026
|
+
declare class BoxCollider implements Collider {
|
|
1027
|
+
/** Collision layer*/
|
|
1028
|
+
layer: string;
|
|
1029
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1030
|
+
physics: boolean;
|
|
1031
|
+
/** Width of the rectangle */
|
|
1032
|
+
width: number;
|
|
1033
|
+
/** Height of the rectangle */
|
|
1034
|
+
height: number;
|
|
1035
|
+
/** X-Y axis offset */
|
|
1036
|
+
offset: Vector2;
|
|
1037
|
+
/** Rectangle rotation in radians */
|
|
1038
|
+
rotation: number;
|
|
1039
|
+
/** Ignores collisions with layers in the array */
|
|
1040
|
+
ignoreCollisionsWithLayers: string[];
|
|
1041
|
+
/** @internal */
|
|
1042
|
+
shapes: Shape[];
|
|
1043
|
+
constructor(options?: Partial<BoxColliderOptions>);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
interface EdgeColliderOptions {
|
|
1047
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
1048
|
+
vertexModel: Vector2[];
|
|
1049
|
+
/** X-Y axis offset */
|
|
1050
|
+
offset: Vector2;
|
|
1051
|
+
/** Edges rotation in radians */
|
|
1052
|
+
rotation: number;
|
|
1053
|
+
/** Collision layer */
|
|
1054
|
+
layer: string;
|
|
1055
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1056
|
+
physics: boolean;
|
|
1057
|
+
/** Ignores collisions with layers in the array */
|
|
1058
|
+
ignoreCollisionsWithLayers: string[];
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Collider composed of lines defined by its vertices, for 2d collisions.
|
|
1062
|
+
* @public
|
|
1063
|
+
* @category Components
|
|
1064
|
+
*/
|
|
1065
|
+
declare class EdgeCollider implements Collider {
|
|
1066
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
1067
|
+
vertexModel: Vector2[];
|
|
1068
|
+
/** X-Y axis offset */
|
|
1069
|
+
offset: Vector2;
|
|
1070
|
+
/** Edges rotation in radians */
|
|
1071
|
+
rotation: number;
|
|
1072
|
+
/** Collision layer */
|
|
1073
|
+
layer: string;
|
|
1074
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1075
|
+
physics: boolean;
|
|
1076
|
+
/** Ignores collisions with layers in the array */
|
|
1077
|
+
ignoreCollisionsWithLayers: string[];
|
|
1078
|
+
/** @internal */
|
|
1079
|
+
shapes: Shape[];
|
|
1080
|
+
constructor(options?: Partial<EdgeColliderOptions>);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
interface PolygonColliderOptions {
|
|
1084
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
1085
|
+
vertexModel: Vector2[];
|
|
1086
|
+
/** X-Y axis offset */
|
|
1087
|
+
offset: Vector2;
|
|
1088
|
+
/** Edges rotation in radians */
|
|
1089
|
+
rotation: number;
|
|
1090
|
+
/** Collision layer */
|
|
1091
|
+
layer: string;
|
|
1092
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1093
|
+
physics: boolean;
|
|
1094
|
+
/** Ignores collisions with layers in the array */
|
|
1095
|
+
ignoreCollisionsWithLayers: string[];
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Polygon shaped Collider for 2d collisions. Only convex polygons are allowed.
|
|
1099
|
+
* @public
|
|
1100
|
+
* @category Components
|
|
1101
|
+
*/
|
|
1102
|
+
declare class PolygonCollider implements Collider {
|
|
1103
|
+
/** Collection of 2d vectors representing the vertices of the collider */
|
|
1104
|
+
vertexModel: Vector2[];
|
|
1105
|
+
/** X-Y axis offset */
|
|
1106
|
+
offset: Vector2;
|
|
1107
|
+
/** Edges rotation in radians */
|
|
1108
|
+
rotation: number;
|
|
1109
|
+
/** Collision layer */
|
|
1110
|
+
layer: string;
|
|
1111
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1112
|
+
physics: boolean;
|
|
1113
|
+
/** Ignores collisions with layers in the array */
|
|
1114
|
+
ignoreCollisionsWithLayers: string[];
|
|
1115
|
+
/** @internal */
|
|
1116
|
+
shapes: Shape[];
|
|
1117
|
+
constructor(options?: Partial<PolygonColliderOptions>);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* The type of the rigid body to create:
|
|
1122
|
+
* - Dynamic: This type of body is affected by gravity and velopcity.
|
|
1123
|
+
* - Static: This type of body is immovable, is unaffected by velocity and gravity.
|
|
1124
|
+
* @category Components
|
|
1125
|
+
* @public
|
|
1126
|
+
*/
|
|
1127
|
+
declare enum RigidBodyType {
|
|
1128
|
+
Dynamic = 0,
|
|
1129
|
+
Static = 1
|
|
1130
|
+
}
|
|
1131
|
+
interface RigidBodyOptions {
|
|
1132
|
+
type: RigidBodyType;
|
|
1133
|
+
velocity: Vector2;
|
|
1134
|
+
gravity: number;
|
|
1135
|
+
acceleration: Vector2;
|
|
1136
|
+
}
|
|
1137
|
+
declare class RigidBody {
|
|
1138
|
+
type: RigidBodyType;
|
|
1139
|
+
velocity: Vector2;
|
|
1140
|
+
gravity: number;
|
|
1141
|
+
acceleration: Vector2;
|
|
1142
|
+
constructor(options?: Partial<RigidBodyOptions>);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
interface TilemapColliderOptions {
|
|
1146
|
+
/** Generate colliders that represent the outer lines of the tile map */
|
|
1147
|
+
composite: boolean;
|
|
1148
|
+
/** Collision layer */
|
|
1149
|
+
layer: string;
|
|
1150
|
+
/** Ignores collisions with layers in the array */
|
|
1151
|
+
ignoreCollisionsWithLayers: string[];
|
|
1152
|
+
/** X-Y axis offset */
|
|
1153
|
+
offset: Vector2;
|
|
1154
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1155
|
+
physics: boolean;
|
|
1156
|
+
}
|
|
1157
|
+
declare class TilemapCollider implements Collider {
|
|
1158
|
+
/** Generate colliders that represent the outer lines of the tile map */
|
|
1159
|
+
composite: boolean;
|
|
1160
|
+
/** Collision layer */
|
|
1161
|
+
layer: string;
|
|
1162
|
+
/** Ignores collisions with layers in the array */
|
|
1163
|
+
ignoreCollisionsWithLayers: string[];
|
|
1164
|
+
/** X-Y axis offset */
|
|
1165
|
+
offset: Vector2;
|
|
1166
|
+
/** TRUE if this collider interact with rigid bodies */
|
|
1167
|
+
physics: boolean;
|
|
1168
|
+
/** @internal */
|
|
1169
|
+
shapes: Shape[];
|
|
1170
|
+
constructor(options?: Partial<TilemapColliderOptions>);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
declare enum RenderDataType {
|
|
1174
|
+
Sprite = 0,
|
|
1175
|
+
Text = 1,
|
|
1176
|
+
Tilemap = 2,
|
|
1177
|
+
Mask = 3,
|
|
1178
|
+
Geometric = 4,
|
|
1179
|
+
Video = 5,
|
|
1180
|
+
Shadow = 6
|
|
1181
|
+
}
|
|
1182
|
+
interface CameraData {
|
|
1183
|
+
depth: number;
|
|
1184
|
+
layers: string[];
|
|
1185
|
+
position: Vector2;
|
|
1186
|
+
zoom: number;
|
|
1187
|
+
}
|
|
1188
|
+
interface RenderData {
|
|
1189
|
+
type: RenderDataType;
|
|
1190
|
+
position: Vector2;
|
|
1191
|
+
layer: string;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Mask shape: Rectangle or Circumference.
|
|
1196
|
+
* @category Components
|
|
1197
|
+
* @public
|
|
1198
|
+
*/
|
|
1199
|
+
declare enum MaskShape {
|
|
1200
|
+
Rectangle = 0,
|
|
1201
|
+
Circumference = 1
|
|
1202
|
+
}
|
|
1203
|
+
interface MaskRenderData extends RenderData {
|
|
1204
|
+
color: string;
|
|
1205
|
+
shape: MaskShape;
|
|
1206
|
+
width: number;
|
|
1207
|
+
height: number;
|
|
1208
|
+
radius: number;
|
|
1209
|
+
rotation: number;
|
|
1210
|
+
opacity: number;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
interface ShadowRenderData extends RenderData {
|
|
1214
|
+
color: string;
|
|
1215
|
+
height: number;
|
|
1216
|
+
opacity: number;
|
|
1217
|
+
rotation: number;
|
|
1218
|
+
width: number;
|
|
1219
|
+
lights: Light[];
|
|
1220
|
+
}
|
|
1221
|
+
interface Light {
|
|
1222
|
+
position: Vector2;
|
|
1223
|
+
radius: number;
|
|
1224
|
+
smooth: boolean;
|
|
1225
|
+
intensity: number;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
interface SpriteRenderData extends RenderData {
|
|
1229
|
+
image: HTMLImageElement;
|
|
1230
|
+
width: number;
|
|
1231
|
+
height: number;
|
|
1232
|
+
smooth?: boolean;
|
|
1233
|
+
slice?: Slice;
|
|
1234
|
+
flipHorizontally?: boolean;
|
|
1235
|
+
flipVertically?: boolean;
|
|
1236
|
+
rotation?: number;
|
|
1237
|
+
opacity?: number;
|
|
1238
|
+
maskColor?: string;
|
|
1239
|
+
maskColorMix?: number;
|
|
1240
|
+
tintColor?: string;
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Cut the image based on straight coordinates starting from the top left downward.
|
|
1244
|
+
* @category Components
|
|
1245
|
+
* @public
|
|
1246
|
+
*/
|
|
1247
|
+
interface Slice {
|
|
1248
|
+
/** Top left x coordinate */
|
|
1249
|
+
x: number;
|
|
1250
|
+
/** Top left y coordinate */
|
|
1251
|
+
y: number;
|
|
1252
|
+
/** The width to slice */
|
|
1253
|
+
width: number;
|
|
1254
|
+
/** The height to slice */
|
|
1255
|
+
height: number;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Direction in which the text will be rendered.
|
|
1260
|
+
* @category Components
|
|
1261
|
+
* @public
|
|
1262
|
+
*/
|
|
1263
|
+
declare enum TextOrientation {
|
|
1264
|
+
Center = 0,
|
|
1265
|
+
RightUp = 1,
|
|
1266
|
+
RightDown = 2,
|
|
1267
|
+
RightCenter = 3
|
|
1268
|
+
}
|
|
1269
|
+
interface TextRenderData extends RenderData {
|
|
1270
|
+
font: FontFace | string;
|
|
1271
|
+
text: string;
|
|
1272
|
+
fontSize: number;
|
|
1273
|
+
color: string;
|
|
1274
|
+
lineSeparation: number;
|
|
1275
|
+
letterSpacing: number;
|
|
1276
|
+
orientation: TextOrientation;
|
|
1277
|
+
rotation: number;
|
|
1278
|
+
opacity: number;
|
|
1279
|
+
smooth: boolean;
|
|
1280
|
+
bitmap: {
|
|
1281
|
+
charRanges: number[];
|
|
1282
|
+
fontSize: number;
|
|
1283
|
+
margin: Vector2;
|
|
1284
|
+
spacing: Vector2;
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Direction in which the tilemap will be rendered.
|
|
1290
|
+
* @category Components
|
|
1291
|
+
* @public
|
|
1292
|
+
*/
|
|
1293
|
+
declare enum TilemapOrientation {
|
|
1294
|
+
Center = 0,
|
|
1295
|
+
RightUp = 1,
|
|
1296
|
+
RightDown = 2,
|
|
1297
|
+
RightCenter = 3
|
|
1298
|
+
}
|
|
1299
|
+
interface TilemapRenderData extends RenderData {
|
|
1300
|
+
tiles: number[];
|
|
1301
|
+
tilemap: {
|
|
1302
|
+
width: number;
|
|
1303
|
+
tileWidth: number;
|
|
1304
|
+
tileHeight: number;
|
|
1305
|
+
height: number;
|
|
1306
|
+
realWidth: number;
|
|
1307
|
+
realHeight: number;
|
|
1308
|
+
};
|
|
1309
|
+
tileset: {
|
|
1310
|
+
image: HTMLImageElement;
|
|
1311
|
+
width: number;
|
|
1312
|
+
tileWidth: number;
|
|
1313
|
+
tileHeight: number;
|
|
1314
|
+
margin?: Vector2;
|
|
1315
|
+
spacing?: Vector2;
|
|
1316
|
+
correction?: Vector2;
|
|
1317
|
+
};
|
|
1318
|
+
smooth?: boolean;
|
|
1319
|
+
flipHorizontal?: boolean;
|
|
1320
|
+
flipVertical?: boolean;
|
|
1321
|
+
rotation?: number;
|
|
1322
|
+
opacity?: number;
|
|
1323
|
+
maskColor?: string;
|
|
1324
|
+
maskColorMix?: number;
|
|
1325
|
+
tintColor?: string;
|
|
1326
|
+
orientation?: TilemapOrientation;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
interface VideoRenderData extends RenderData {
|
|
1330
|
+
video: HTMLVideoElement;
|
|
1331
|
+
width: number;
|
|
1332
|
+
height: number;
|
|
1333
|
+
slice?: Slice;
|
|
1334
|
+
flipHorizontal?: boolean;
|
|
1335
|
+
flipVertical?: boolean;
|
|
1336
|
+
rotation?: number;
|
|
1337
|
+
opacity?: number;
|
|
1338
|
+
maskColor?: string;
|
|
1339
|
+
maskColorMix?: number;
|
|
1340
|
+
tintColor?: string;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
declare const defaultRenderLayer = "Default";
|
|
1344
|
+
/**
|
|
1345
|
+
* @public
|
|
1346
|
+
* @category Components
|
|
1347
|
+
*/
|
|
1348
|
+
interface CameraOptions {
|
|
1349
|
+
layers: string[];
|
|
1350
|
+
zoom: number;
|
|
1351
|
+
depth: number;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* @public
|
|
1355
|
+
* @category Components
|
|
1356
|
+
*/
|
|
1357
|
+
declare class Camera {
|
|
1358
|
+
/** Layers to be rendered by this camera. Layers are rendered in ascending order */
|
|
1359
|
+
layers: string[];
|
|
1360
|
+
/** Camera zoom. Default value is 1 */
|
|
1361
|
+
zoom: number;
|
|
1362
|
+
/** In case you have more than one camera, the depth value determines which camera is rendered first. The lesser value, the first to render */
|
|
1363
|
+
depth: number;
|
|
1364
|
+
/** @internal */
|
|
1365
|
+
_renderData: CameraData;
|
|
1366
|
+
constructor(options?: Partial<CameraOptions>);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* @public
|
|
1371
|
+
* @category Components
|
|
1372
|
+
*/
|
|
1373
|
+
interface LightRendererOptions {
|
|
1374
|
+
radius: number;
|
|
1375
|
+
smooth: boolean;
|
|
1376
|
+
layer: string;
|
|
1377
|
+
intensity: number;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* @public
|
|
1381
|
+
* @category Components
|
|
1382
|
+
*/
|
|
1383
|
+
declare class LightRenderer {
|
|
1384
|
+
/** Light radius */
|
|
1385
|
+
radius: number;
|
|
1386
|
+
/** Smooth */
|
|
1387
|
+
smooth: boolean;
|
|
1388
|
+
/** Shadow render layer */
|
|
1389
|
+
layer: string;
|
|
1390
|
+
/** Light intensitry between 0 and 1 */
|
|
1391
|
+
intensity: number;
|
|
1392
|
+
/** @internal */
|
|
1393
|
+
_boundingBox: Rectangle;
|
|
1394
|
+
constructor(options?: Partial<LightRendererOptions>);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* @public
|
|
1399
|
+
* @category Components
|
|
1400
|
+
*/
|
|
1401
|
+
interface MaskRendererOptions {
|
|
1402
|
+
shape: MaskShape;
|
|
1403
|
+
color: string;
|
|
1404
|
+
width: number;
|
|
1405
|
+
height: number;
|
|
1406
|
+
radius: number;
|
|
1407
|
+
offset: Vector2;
|
|
1408
|
+
rotation: number;
|
|
1409
|
+
opacity: number;
|
|
1410
|
+
layer: string;
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Renders a filled shape (rectangle or circumference)
|
|
1414
|
+
* @public
|
|
1415
|
+
* @category Components
|
|
1416
|
+
* @example
|
|
1417
|
+
* ```js
|
|
1418
|
+
* maskRenderer.shape = MaskShape.Rectangle;
|
|
1419
|
+
* maskRenderer.width = 32;
|
|
1420
|
+
* maskRenderer.height = 32;
|
|
1421
|
+
* maskRenderer.color = "#000000";
|
|
1422
|
+
* maskRenderer.offset = new Vector2(0, 0);
|
|
1423
|
+
* maskRenderer.rotation = 0;
|
|
1424
|
+
* maskRenderer.opacity = 1;
|
|
1425
|
+
* maskRenderer.layer = "Default";
|
|
1426
|
+
* ```
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```js
|
|
1429
|
+
* maskRenderer.shape = MaskShape.Circumference;
|
|
1430
|
+
* maskRenderer.radius = 16;
|
|
1431
|
+
* maskRenderer.color = "#000000";
|
|
1432
|
+
* maskRenderer.offset = new Vector2(0, 0);
|
|
1433
|
+
* maskRenderer.opacity = 1;
|
|
1434
|
+
* maskRenderer.layer = "Default";
|
|
1435
|
+
* ```
|
|
1436
|
+
*/
|
|
1437
|
+
declare class MaskRenderer {
|
|
1438
|
+
/** Mask shape: Rectangle or Circumference */
|
|
1439
|
+
shape: MaskShape;
|
|
1440
|
+
/** Mask width in pixels */
|
|
1441
|
+
width: number;
|
|
1442
|
+
/** Mask height in pixels */
|
|
1443
|
+
height: number;
|
|
1444
|
+
/** Mask radius in pixels (only for circumference) */
|
|
1445
|
+
radius: number;
|
|
1446
|
+
/** The color of the mask */
|
|
1447
|
+
color: string;
|
|
1448
|
+
/** X-axis and Y-axis offset */
|
|
1449
|
+
offset: Vector2;
|
|
1450
|
+
/** Mask rotation in radians */
|
|
1451
|
+
rotation: number;
|
|
1452
|
+
/** Change the opacity between 1 and 0 */
|
|
1453
|
+
opacity: number;
|
|
1454
|
+
/** The render layer */
|
|
1455
|
+
layer: string;
|
|
1456
|
+
/** @internal */
|
|
1457
|
+
_renderData: MaskRenderData;
|
|
1458
|
+
constructor(options?: Partial<MaskRendererOptions>);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* @public
|
|
1463
|
+
* @category Components
|
|
1464
|
+
*/
|
|
1465
|
+
interface ShadowRendererOptions {
|
|
1466
|
+
width: number;
|
|
1467
|
+
height: number;
|
|
1468
|
+
color: string;
|
|
1469
|
+
opacity: number;
|
|
1470
|
+
layer: string;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* @public
|
|
1474
|
+
* @category Components
|
|
1475
|
+
*/
|
|
1476
|
+
declare class ShadowRenderer {
|
|
1477
|
+
/** Shadow width */
|
|
1478
|
+
width: number;
|
|
1479
|
+
/** Shadow height */
|
|
1480
|
+
height: number;
|
|
1481
|
+
/** Shadow color */
|
|
1482
|
+
color: string;
|
|
1483
|
+
/** Shadow opacity between 0 and 1 */
|
|
1484
|
+
opacity: number;
|
|
1485
|
+
/** The render layer */
|
|
1486
|
+
layer: string;
|
|
1487
|
+
/** @internal */
|
|
1488
|
+
_boundingBox: Rectangle;
|
|
1489
|
+
/** @internal */
|
|
1490
|
+
_renderData: ShadowRenderData;
|
|
1491
|
+
constructor(options?: Partial<ShadowRendererOptions>);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* @public
|
|
1496
|
+
* @category Components
|
|
1497
|
+
*/
|
|
1498
|
+
interface SpriteRendererOptions {
|
|
1499
|
+
image: HTMLImageElement;
|
|
1500
|
+
layer: string;
|
|
1501
|
+
slice: Slice;
|
|
1502
|
+
smooth: boolean;
|
|
1503
|
+
offset: Vector2;
|
|
1504
|
+
flipHorizontally: boolean;
|
|
1505
|
+
flipVertically: boolean;
|
|
1506
|
+
rotation: number;
|
|
1507
|
+
opacity: number;
|
|
1508
|
+
maskColor: string;
|
|
1509
|
+
maskColorMix: number;
|
|
1510
|
+
tintColor: string;
|
|
1511
|
+
scale: Vector2;
|
|
1512
|
+
width: number;
|
|
1513
|
+
height: number;
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* @public
|
|
1517
|
+
* @category Components
|
|
1518
|
+
*/
|
|
1519
|
+
declare class SpriteRenderer {
|
|
1520
|
+
/** The render layer */
|
|
1521
|
+
layer: string;
|
|
1522
|
+
/** The image to render */
|
|
1523
|
+
image: HTMLImageElement;
|
|
1524
|
+
/** Cut the image based on straight coordinates starting from the top left downward */
|
|
1525
|
+
slice?: Slice;
|
|
1526
|
+
/** TRUE for smooth pixels (not recommended for pixel art) */
|
|
1527
|
+
smooth: boolean;
|
|
1528
|
+
/** X-axis and Y-axis offset */
|
|
1529
|
+
offset: Vector2;
|
|
1530
|
+
/** Flip the image horizontally */
|
|
1531
|
+
flipHorizontally: boolean;
|
|
1532
|
+
/** Flip the image vertically */
|
|
1533
|
+
flipVertically: boolean;
|
|
1534
|
+
/** Image rotation in radians */
|
|
1535
|
+
rotation: number;
|
|
1536
|
+
/** Change the opacity between 1 and 0 */
|
|
1537
|
+
opacity: number;
|
|
1538
|
+
/** Define a mask color for the image */
|
|
1539
|
+
maskColor: string;
|
|
1540
|
+
/** Define the opacity of the mask color between 1 and 0 */
|
|
1541
|
+
maskColorMix: number;
|
|
1542
|
+
/** Define a color for tinting the sprite image */
|
|
1543
|
+
tintColor: string;
|
|
1544
|
+
/** Scale the image based on a vector */
|
|
1545
|
+
scale: Vector2;
|
|
1546
|
+
/** Overwrite the original image width */
|
|
1547
|
+
width: number;
|
|
1548
|
+
/** Overwrite the original image height */
|
|
1549
|
+
height: number;
|
|
1550
|
+
/** @internal */
|
|
1551
|
+
_renderData: SpriteRenderData;
|
|
1552
|
+
constructor(options?: Partial<SpriteRendererOptions>);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* @public
|
|
1557
|
+
* @category Components
|
|
1558
|
+
*/
|
|
1559
|
+
interface TextRendererOptions {
|
|
1560
|
+
layer: string;
|
|
1561
|
+
text: string;
|
|
1562
|
+
font: FontFace | string;
|
|
1563
|
+
fontSize: number;
|
|
1564
|
+
width: number;
|
|
1565
|
+
height: number;
|
|
1566
|
+
offset: Vector2;
|
|
1567
|
+
color: string;
|
|
1568
|
+
lineSeparation: number;
|
|
1569
|
+
letterSpacing: number;
|
|
1570
|
+
charRanges: number[];
|
|
1571
|
+
smooth: boolean;
|
|
1572
|
+
rotation: number;
|
|
1573
|
+
opacity: number;
|
|
1574
|
+
orientation: TextOrientation;
|
|
1575
|
+
bitmapMargin: Vector2;
|
|
1576
|
+
bitmapSpacing: Vector2;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* The TextRenderer component allows to render text using font families, colors, and other configuration options.
|
|
1580
|
+
* @public
|
|
1581
|
+
* @category Components
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```js
|
|
1584
|
+
* textRenderer.layer: "default";
|
|
1585
|
+
* textRenderer.text: "Hello world!";
|
|
1586
|
+
* textRenderer.font: "Arial";
|
|
1587
|
+
* textRenderer.fontSize: 16;
|
|
1588
|
+
* textRenderer.width: 160;
|
|
1589
|
+
* textRenderer.height: 16;
|
|
1590
|
+
* textRenderer.color: "#000000";
|
|
1591
|
+
* textRenderer.offset: new Vector2();
|
|
1592
|
+
* textRenderer.lineSeparation: 0;
|
|
1593
|
+
* textRenderer.letterSpacing: 0;
|
|
1594
|
+
* textRenderer.charRanges: [32, 126, 161, 255];
|
|
1595
|
+
* textRenderer.smooth: false;
|
|
1596
|
+
* textRenderer.rotation: 0;
|
|
1597
|
+
* textRenderer.opacity: 1;
|
|
1598
|
+
* textRenderer.orientation: TextOrientation.RightDown;
|
|
1599
|
+
* textRenderer.bitmapMargin: new Vector2();
|
|
1600
|
+
* textRenderer.bitmapSpacing: new Vector2();
|
|
1601
|
+
* ```
|
|
1602
|
+
*/
|
|
1603
|
+
declare class TextRenderer {
|
|
1604
|
+
/** The render layer */
|
|
1605
|
+
layer: string;
|
|
1606
|
+
/** The text to render */
|
|
1607
|
+
text: string;
|
|
1608
|
+
/** The font family to use */
|
|
1609
|
+
font: FontFace | string;
|
|
1610
|
+
/** The size of the font in pixels. */
|
|
1611
|
+
fontSize: number;
|
|
1612
|
+
/** The width of the invisible box where the text is rendered */
|
|
1613
|
+
width: number;
|
|
1614
|
+
/** The height of the invisible box where the text is rendered */
|
|
1615
|
+
height: number;
|
|
1616
|
+
/** X-axis and Y-axis offset */
|
|
1617
|
+
offset: Vector2;
|
|
1618
|
+
/** The text color */
|
|
1619
|
+
color: string;
|
|
1620
|
+
/** The separation between lines in pixels */
|
|
1621
|
+
lineSeparation: number;
|
|
1622
|
+
/** The space between chars in pixels */
|
|
1623
|
+
letterSpacing: number;
|
|
1624
|
+
/** Range of characters covered by the component defined in number pairs.
|
|
1625
|
+
* The default value is [32, 126, 161, 255], this means that the component
|
|
1626
|
+
* will render characters from 32 to 126 and from 161 to 255. */
|
|
1627
|
+
charRanges: number[];
|
|
1628
|
+
/** Smoothing pixels (not recommended for bitmap fonts) */
|
|
1629
|
+
smooth: boolean;
|
|
1630
|
+
/** Text rotation in radians */
|
|
1631
|
+
rotation: number;
|
|
1632
|
+
/** Change the opacity between 1 and 0 */
|
|
1633
|
+
opacity: number;
|
|
1634
|
+
/** Direction in which the text will be rendered. */
|
|
1635
|
+
orientation: TextOrientation;
|
|
1636
|
+
/** Margin in pixels to correct badly sliced characters. */
|
|
1637
|
+
bitmapMargin: Vector2;
|
|
1638
|
+
/** Spacing in pixels to correct badly sliced characters. */
|
|
1639
|
+
bitmapSpacing: Vector2;
|
|
1640
|
+
/** @internal */
|
|
1641
|
+
_renderData: TextRenderData;
|
|
1642
|
+
constructor(options?: Partial<TextRendererOptions>);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* @public
|
|
1647
|
+
* @category Components
|
|
1648
|
+
*/
|
|
1649
|
+
interface TilemapRendererOptions {
|
|
1650
|
+
layer: string;
|
|
1651
|
+
tileset: Tileset;
|
|
1652
|
+
data: number[];
|
|
1653
|
+
chunks: Chunk[];
|
|
1654
|
+
width: number;
|
|
1655
|
+
height: number;
|
|
1656
|
+
tileWidth: number;
|
|
1657
|
+
tileHeight: number;
|
|
1658
|
+
tintColor: string;
|
|
1659
|
+
opacity: number;
|
|
1660
|
+
smooth: boolean;
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* The TilemapRenderer component allows you to render a tile map defined by an array of tile ids, using an instance of the TileSet object.
|
|
1664
|
+
* @public
|
|
1665
|
+
* @category Components
|
|
1666
|
+
*/
|
|
1667
|
+
declare class TilemapRenderer {
|
|
1668
|
+
/** The render layer */
|
|
1669
|
+
layer: string;
|
|
1670
|
+
/** The Tileset instance */
|
|
1671
|
+
tileset: Tileset;
|
|
1672
|
+
/** Array of tiles. ID 0 (zero) represents empty space.*/
|
|
1673
|
+
data: number[];
|
|
1674
|
+
/** Array of tile data split into chunks */
|
|
1675
|
+
chunks: Chunk[];
|
|
1676
|
+
/** The width of the tilemap (in tiles) */
|
|
1677
|
+
width: number;
|
|
1678
|
+
/** The height of the tilemap (in tiles) */
|
|
1679
|
+
height: number;
|
|
1680
|
+
/** The width of the tile to render */
|
|
1681
|
+
tileWidth: number;
|
|
1682
|
+
/** The height of the tile to render */
|
|
1683
|
+
tileHeight: number;
|
|
1684
|
+
/** Define a color for tinting the tiles */
|
|
1685
|
+
tintColor: string;
|
|
1686
|
+
/** Change the opacity between 1 and 0 */
|
|
1687
|
+
opacity: number;
|
|
1688
|
+
/** TRUE for smooth pixels (not recommended for pixel art) */
|
|
1689
|
+
smooth: boolean;
|
|
1690
|
+
/** @internal */
|
|
1691
|
+
_processed: boolean;
|
|
1692
|
+
/** @internal */
|
|
1693
|
+
_renderData: TilemapRenderData[];
|
|
1694
|
+
constructor(options?: Partial<TilemapRendererOptions>);
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Tileset configuration to be used with the TilemapRenderer
|
|
1698
|
+
* @public
|
|
1699
|
+
* @category Components
|
|
1700
|
+
*/
|
|
1701
|
+
type Tileset = {
|
|
1702
|
+
/** The tileset image element */
|
|
1703
|
+
image: HTMLImageElement;
|
|
1704
|
+
width: number;
|
|
1705
|
+
tileWidth: number;
|
|
1706
|
+
tileHeight: number;
|
|
1707
|
+
/** Margin of the tile in pixels (space in the top and the left) */
|
|
1708
|
+
margin?: Vector2;
|
|
1709
|
+
/** Spacing of the tile in pixels (space in the bottom and the right) */
|
|
1710
|
+
spacing?: Vector2;
|
|
1711
|
+
};
|
|
1712
|
+
/**
|
|
1713
|
+
* Chunk of tile data
|
|
1714
|
+
* @public
|
|
1715
|
+
* @category Components
|
|
1716
|
+
*/
|
|
1717
|
+
type Chunk = {
|
|
1718
|
+
/** Array of tiles. ID 0 (zero) represents empty space.*/
|
|
1719
|
+
data: number[];
|
|
1720
|
+
x: number;
|
|
1721
|
+
y: number;
|
|
1722
|
+
/** Chunk width (in tails) */
|
|
1723
|
+
width: number;
|
|
1724
|
+
/** Chunk height (in tails) */
|
|
1725
|
+
height: number;
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
/**
|
|
1729
|
+
* @public
|
|
1730
|
+
* @category Components
|
|
1731
|
+
*/
|
|
1732
|
+
interface VideoRendererOptions {
|
|
1733
|
+
video: HTMLVideoElement;
|
|
1734
|
+
width: number;
|
|
1735
|
+
height: number;
|
|
1736
|
+
offset: Vector2;
|
|
1737
|
+
rotation: number;
|
|
1738
|
+
flipHorizontally: boolean;
|
|
1739
|
+
flipVertically: boolean;
|
|
1740
|
+
opacity: number;
|
|
1741
|
+
maskColor: string;
|
|
1742
|
+
maskColorMix: number;
|
|
1743
|
+
tintColor: string;
|
|
1744
|
+
layer: string;
|
|
1745
|
+
slice: Slice;
|
|
1746
|
+
loop: boolean;
|
|
1747
|
+
volume: number;
|
|
1748
|
+
play: boolean;
|
|
1749
|
+
pause: boolean;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* The VideoRenderer component plays and renders a video element,
|
|
1753
|
+
* and allows configuring options such as its dimensions, coloring, etc.
|
|
1754
|
+
* @public
|
|
1755
|
+
* @category Components
|
|
1756
|
+
* @example
|
|
1757
|
+
* ```js
|
|
1758
|
+
* videoRenderer.video = this.assetManager.getVideo("video.mp4");
|
|
1759
|
+
* videoRenderer.width = 1920;
|
|
1760
|
+
* videoRenderer.height = 1080;
|
|
1761
|
+
* videoRenderer.offset = new Vector2(0, 0);
|
|
1762
|
+
* videoRenderer.flipHorizontally = false;
|
|
1763
|
+
* videoRenderer.flipVertically = false;
|
|
1764
|
+
* videoRenderer.rotation = 0;
|
|
1765
|
+
* videoRenderer.opacity = 1;
|
|
1766
|
+
* videoRenderer.maskColor = "#FF0000";
|
|
1767
|
+
* videoRenderer.maskColorMix = 0;
|
|
1768
|
+
* videoRenderer.tintColor = "#00FF00";
|
|
1769
|
+
* videoRenderer.layer = "Default";
|
|
1770
|
+
* videoRenderer.slice = {x: 0, y:0, width: 1920, height: 1080};
|
|
1771
|
+
* videoRenderer.volume = 1;
|
|
1772
|
+
* videoRenderer.loop = false;
|
|
1773
|
+
* videoRenderer.play = true;
|
|
1774
|
+
* videoRenderer.pause = false;
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
declare class VideoRenderer {
|
|
1778
|
+
/**The video element to render */
|
|
1779
|
+
video: HTMLVideoElement;
|
|
1780
|
+
/** Overwrite the original video width */
|
|
1781
|
+
width: number;
|
|
1782
|
+
/** Overwrite the original video height */
|
|
1783
|
+
height: number;
|
|
1784
|
+
/** X-axis and Y-axis offset */
|
|
1785
|
+
offset: Vector2;
|
|
1786
|
+
/** Video rotation (degrees or radians) */
|
|
1787
|
+
rotation: number;
|
|
1788
|
+
/** Flip the video horizontally */
|
|
1789
|
+
flipHorizontally: boolean;
|
|
1790
|
+
/** Flip the video vertically */
|
|
1791
|
+
flipVertically: boolean;
|
|
1792
|
+
/** Change the opacity between 1 and 0 */
|
|
1793
|
+
opacity: number;
|
|
1794
|
+
/** Define a mask color for the video */
|
|
1795
|
+
maskColor: string;
|
|
1796
|
+
/** Define the opacity of the mask color between 1 and 0 */
|
|
1797
|
+
maskColorMix: number;
|
|
1798
|
+
/** Define a color for tinting the video */
|
|
1799
|
+
tintColor: string;
|
|
1800
|
+
/** The render layer */
|
|
1801
|
+
layer: string;
|
|
1802
|
+
/** Cut the video based on straight coordinates starting from the top left downward */
|
|
1803
|
+
slice?: Slice;
|
|
1804
|
+
/** TRUE to play the video in loop */
|
|
1805
|
+
loop: boolean;
|
|
1806
|
+
/** The volume of the video (between 1 and 0) */
|
|
1807
|
+
volume: number;
|
|
1808
|
+
/** TRUE to play the video. If the video stops playing it becomes FALSE */
|
|
1809
|
+
play: boolean;
|
|
1810
|
+
/** TRUE to pause the video */
|
|
1811
|
+
pause: boolean;
|
|
1812
|
+
/** @internal */
|
|
1813
|
+
_renderData: VideoRenderData;
|
|
1814
|
+
constructor(options?: Partial<VideoRendererOptions>);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
/**
|
|
1818
|
+
* It represents a connected gamepad and has the information of all its buttons and axes..
|
|
1819
|
+
* @public
|
|
1820
|
+
* @category Input
|
|
1821
|
+
* @example
|
|
1822
|
+
* ```js
|
|
1823
|
+
* const gamepad = this.inputManager.gamepads[0];
|
|
1824
|
+
*
|
|
1825
|
+
* if (gamepad.dpadAxes.x > 1) {
|
|
1826
|
+
* // if the depad x-axis is pressed to the right, do some action
|
|
1827
|
+
* }
|
|
1828
|
+
*
|
|
1829
|
+
* if (gamepad.rightFace) {
|
|
1830
|
+
* // if the right face button is pressed, do some action
|
|
1831
|
+
* }
|
|
1832
|
+
* ```
|
|
1833
|
+
*/
|
|
1834
|
+
declare class GamepadController {
|
|
1835
|
+
/** @internal */
|
|
1836
|
+
readonly buttons: Map<number, boolean>;
|
|
1837
|
+
/** @internal */
|
|
1838
|
+
readonly axes: Map<number, number>;
|
|
1839
|
+
private readonly _dpadAxes;
|
|
1840
|
+
private readonly _leftStickAxes;
|
|
1841
|
+
private readonly _rightStickAxes;
|
|
1842
|
+
/**
|
|
1843
|
+
* The gamepad id
|
|
1844
|
+
*/
|
|
1845
|
+
id: string;
|
|
1846
|
+
/**
|
|
1847
|
+
* The gamepad index
|
|
1848
|
+
*/
|
|
1849
|
+
index: number;
|
|
1850
|
+
/**
|
|
1851
|
+
* TRUE if the gamepad is connected
|
|
1852
|
+
*/
|
|
1853
|
+
connected: boolean;
|
|
1854
|
+
/**
|
|
1855
|
+
* The values of the d-pad axes represented as a xy vector
|
|
1856
|
+
*/
|
|
1857
|
+
get dpadAxes(): Vector2;
|
|
1858
|
+
/**
|
|
1859
|
+
* The values of the left stick axes represented as a xy vector
|
|
1860
|
+
*/
|
|
1861
|
+
get leftStickAxes(): Vector2;
|
|
1862
|
+
/**
|
|
1863
|
+
* The values of the right stick axes represented as a xy vector
|
|
1864
|
+
*/
|
|
1865
|
+
get rightStickAxes(): Vector2;
|
|
1866
|
+
/**
|
|
1867
|
+
* TRUE if d-pad up is pressed
|
|
1868
|
+
*/
|
|
1869
|
+
get dpadUp(): boolean;
|
|
1870
|
+
/**
|
|
1871
|
+
* TRUE if d-pad down is pressed
|
|
1872
|
+
*/
|
|
1873
|
+
get dpadDown(): boolean;
|
|
1874
|
+
/**
|
|
1875
|
+
* TRUE if d-pad left is pressed
|
|
1876
|
+
*/
|
|
1877
|
+
get dpadLeft(): boolean;
|
|
1878
|
+
/**
|
|
1879
|
+
* TRUE if d-pad right is pressed
|
|
1880
|
+
*/
|
|
1881
|
+
get dpadRight(): boolean;
|
|
1882
|
+
/**
|
|
1883
|
+
* TRUE if bottom face button is pressed (Dual Shock: X. Xbox: A. Nintendo: B)
|
|
1884
|
+
*/
|
|
1885
|
+
get bottomFace(): boolean;
|
|
1886
|
+
/**
|
|
1887
|
+
* TRUE if right face button is pressed (Dual Shock: Square. Xbox: X. Nintendo: Y)
|
|
1888
|
+
*/
|
|
1889
|
+
get rightFace(): boolean;
|
|
1890
|
+
/**
|
|
1891
|
+
* TRUE if left face button is pressed (Dual Shock: Circle. Xbox: B. Nintendo: A)
|
|
1892
|
+
*/
|
|
1893
|
+
get leftFace(): boolean;
|
|
1894
|
+
/**
|
|
1895
|
+
* TRUE if top face button is pressed (Dual Shock: Triangle. Xbox: Y. Nintendo: X)
|
|
1896
|
+
*/
|
|
1897
|
+
get topFace(): boolean;
|
|
1898
|
+
/**
|
|
1899
|
+
* TRUE if left shoulder button is pressed (Dual Shock: L1. Xbox: LB. Nintendo: L)
|
|
1900
|
+
*/
|
|
1901
|
+
get leftShoulder(): boolean;
|
|
1902
|
+
/**
|
|
1903
|
+
* TRUE if right shoulder button is pressed (Dual Shock: R1. Xbox: RB. Nintendo: R)
|
|
1904
|
+
*/
|
|
1905
|
+
get rightShoulder(): boolean;
|
|
1906
|
+
/**
|
|
1907
|
+
* TRUE if left trigger button is pressed (Dual Shock: L2. Xbox: LT. Nintendo: ZL)
|
|
1908
|
+
*/
|
|
1909
|
+
get leftTrigger(): boolean;
|
|
1910
|
+
/**
|
|
1911
|
+
* TRUE if right trigger button is pressed (Dual Shock: R2. Xbox: RT. Nintendo: ZR)
|
|
1912
|
+
*/
|
|
1913
|
+
get rightTrigger(): boolean;
|
|
1914
|
+
/**
|
|
1915
|
+
* TRUE if back button is pressed (a.k.a. select button)
|
|
1916
|
+
*/
|
|
1917
|
+
get back(): boolean;
|
|
1918
|
+
/**
|
|
1919
|
+
* TRUE if start button is pressed (a.k.a. options button)
|
|
1920
|
+
*/
|
|
1921
|
+
get start(): boolean;
|
|
1922
|
+
/**
|
|
1923
|
+
* TRUE if left stick button is pressed
|
|
1924
|
+
*/
|
|
1925
|
+
get leftStickButton(): boolean;
|
|
1926
|
+
/**
|
|
1927
|
+
* TRUE if right stick button is pressed
|
|
1928
|
+
*/
|
|
1929
|
+
get rightStickButton(): boolean;
|
|
1930
|
+
/**
|
|
1931
|
+
* Left stick horizontal axes value
|
|
1932
|
+
*/
|
|
1933
|
+
get leftStickHorizontal(): number;
|
|
1934
|
+
/**
|
|
1935
|
+
* Left stick vertical axes value
|
|
1936
|
+
*/
|
|
1937
|
+
get leftStickVertical(): number;
|
|
1938
|
+
/**
|
|
1939
|
+
* Right stick horizontal axes value
|
|
1940
|
+
*/
|
|
1941
|
+
get rightStickHorizontal(): number;
|
|
1942
|
+
/**
|
|
1943
|
+
* Right stick vertical axes value
|
|
1944
|
+
*/
|
|
1945
|
+
get rightStickVertical(): number;
|
|
1946
|
+
/**
|
|
1947
|
+
* TRUE if any button is pressed
|
|
1948
|
+
*/
|
|
1949
|
+
get anyButtonPressed(): boolean;
|
|
1950
|
+
/**
|
|
1951
|
+
* TRUE if the vibration is on
|
|
1952
|
+
*/
|
|
1953
|
+
vibrating: boolean;
|
|
1954
|
+
/**
|
|
1955
|
+
* @internal
|
|
1956
|
+
*/
|
|
1957
|
+
vibrationInput: VibrationInput;
|
|
1958
|
+
/**
|
|
1959
|
+
* Turns on the gamepad vibration
|
|
1960
|
+
* @param duration The duration of the effect in milliseconds
|
|
1961
|
+
* @param weakMagnitude Rumble intensity of the high-frequency (weak) rumble motors, normalized to the range between 0.0 and 1.0
|
|
1962
|
+
* @param strongMagnitude Rumble intensity of the low-frequency (strong) rumble motors, normalized to the range between 0.0 and 1.0
|
|
1963
|
+
* @param startDelay The delay in milliseconds before the effect is started
|
|
1964
|
+
*/
|
|
1965
|
+
vibrate(duration?: number, weakMagnitude?: number, strongMagnitude?: number, startDelay?: number): void;
|
|
1966
|
+
}
|
|
1967
|
+
type VibrationInput = {
|
|
1968
|
+
duration: number;
|
|
1969
|
+
weakMagnitude: number;
|
|
1970
|
+
strongMagnitude: number;
|
|
1971
|
+
startDelay: number;
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
/**
|
|
1975
|
+
* Contains the keyboard information in the last frame.
|
|
1976
|
+
* It uses the **code** property of the **js keyboard event**.
|
|
1977
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
1978
|
+
* @public
|
|
1979
|
+
* @category Input
|
|
1980
|
+
* @example
|
|
1981
|
+
* ```js
|
|
1982
|
+
* const keyboard = this.inputManager.keyboard;
|
|
1983
|
+
*
|
|
1984
|
+
* if (keyboard.isPressed("ArrowRight")) {
|
|
1985
|
+
* // if the right arrow key is pressed, do some action
|
|
1986
|
+
* }
|
|
1987
|
+
*
|
|
1988
|
+
* if (keyboard.orPressed("Enter", "Space")) {
|
|
1989
|
+
* // if the enter key or space key are pressed, do some action
|
|
1990
|
+
* }
|
|
1991
|
+
*
|
|
1992
|
+
* if (keyboard.andPressed("ControlLeft", "KeyC")) {
|
|
1993
|
+
* // if the left control key and the letter C key are pressed, do some action
|
|
1994
|
+
* }
|
|
1995
|
+
* ```
|
|
1996
|
+
*/
|
|
1997
|
+
declare class Keyboard {
|
|
1998
|
+
/**
|
|
1999
|
+
* The current pressed key codes
|
|
2000
|
+
*/
|
|
2001
|
+
pressedKeys: string[];
|
|
2002
|
+
/**
|
|
2003
|
+
* Returns TRUE if the given key is being pressed.
|
|
2004
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2005
|
+
* @param keyCode The code of the key to check
|
|
2006
|
+
* @returns TRUE true for pressed, FALSE instead
|
|
2007
|
+
*/
|
|
2008
|
+
isPressed(keyCode: string): boolean;
|
|
2009
|
+
/**
|
|
2010
|
+
* Returns TRUE if one of the given keys is being pressed.
|
|
2011
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2012
|
+
* @param keyCodes The codes of the keys to check
|
|
2013
|
+
* @returns TRUE for pressed, FALSE instead
|
|
2014
|
+
*/
|
|
2015
|
+
orPressed(keyCodes: string[]): boolean;
|
|
2016
|
+
/**
|
|
2017
|
+
* Returns TRUE if all the given keys are being pressed.
|
|
2018
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2019
|
+
* @param keyCodes The codes of the keys to check
|
|
2020
|
+
* @returns TRUE for pressed, FALSE instead
|
|
2021
|
+
*/
|
|
2022
|
+
andPressed(keyCodes: string[]): boolean;
|
|
2023
|
+
/**
|
|
2024
|
+
* This method accepts two parameters that will be returned depending on whether the key is pressed or not.
|
|
2025
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2026
|
+
* @param keyCode The code of the key to check
|
|
2027
|
+
* @param returnTrue The value to return if the key is pressed
|
|
2028
|
+
* @param returnFalse The value to return if the key is not pressed
|
|
2029
|
+
* @returns The returnTrue for pressed or the returnFalse instead
|
|
2030
|
+
*/
|
|
2031
|
+
isPressedReturn<T>(keyCode: string, returnTrue: T, returnFalse: T): T;
|
|
2032
|
+
/**
|
|
2033
|
+
* This method accepts two parameters that will be returned depending on whether one of the given keys is being pressed.
|
|
2034
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2035
|
+
* @param keyCodes The codes of the keys to check
|
|
2036
|
+
* @param returnTrue The value to return if the key is pressed
|
|
2037
|
+
* @param returnFalse The value to return if the key is not pressed
|
|
2038
|
+
* @returns The returnTrue for pressed or the returnFalse instead
|
|
2039
|
+
*/
|
|
2040
|
+
orPressedReturn<T>(keyCodes: string[], returnTrue: T, returnFalse: T): T;
|
|
2041
|
+
/**
|
|
2042
|
+
* This method accepts two parameters that will be returned depending on whether all the given keys are being pressed.
|
|
2043
|
+
* @see [KeyboardEvent: code property](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)
|
|
2044
|
+
* @param keyCodes The codes of the keys to check
|
|
2045
|
+
* @param returnTrue The value to return if the key is pressed
|
|
2046
|
+
* @param returnFalse The value to return if the key is not pressed
|
|
2047
|
+
* @returns The returnTrue for pressed or the returnFalse instead
|
|
2048
|
+
*/
|
|
2049
|
+
andPressedReturn<T>(keyCodes: string[], returnTrue: T, returnFalse: T): T;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
/**
|
|
2053
|
+
* Contains the mouse information in the last frame
|
|
2054
|
+
* @public
|
|
2055
|
+
* @category Input
|
|
2056
|
+
* @example
|
|
2057
|
+
* ```js
|
|
2058
|
+
* const mouse = this.inputManager.mouse;
|
|
2059
|
+
*
|
|
2060
|
+
* if (mouse.positionInViewport.y < 0 && mouse.leftButtonPressed) {
|
|
2061
|
+
* // if the mouse pointer is below the middle of the screen and left click, do something
|
|
2062
|
+
* }
|
|
2063
|
+
* ```
|
|
2064
|
+
*/
|
|
2065
|
+
declare class Mouse {
|
|
2066
|
+
/**
|
|
2067
|
+
* TRUE if the left button is being pressed
|
|
2068
|
+
*/
|
|
2069
|
+
leftButtonPressed: boolean;
|
|
2070
|
+
/**
|
|
2071
|
+
* TRUE if the scroll button is being pressed
|
|
2072
|
+
*/
|
|
2073
|
+
scrollButtonPressed: boolean;
|
|
2074
|
+
/**
|
|
2075
|
+
* TRUE if the right button is beign pressed
|
|
2076
|
+
*/
|
|
2077
|
+
rightButtonPressed: boolean;
|
|
2078
|
+
/**
|
|
2079
|
+
* The position of the pointer in the screen view port
|
|
2080
|
+
*/
|
|
2081
|
+
positionInViewport: Vector2;
|
|
2082
|
+
/**
|
|
2083
|
+
* TRUE if the mouse moved during the last frame
|
|
2084
|
+
*/
|
|
2085
|
+
hasMoved: boolean;
|
|
2086
|
+
/**
|
|
2087
|
+
* The scroll amount of the mouse wheel
|
|
2088
|
+
*/
|
|
2089
|
+
wheelScroll: Vector2;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
/**
|
|
2093
|
+
* The information about one interaction with the screen
|
|
2094
|
+
* @public
|
|
2095
|
+
* @category Input
|
|
2096
|
+
*/
|
|
2097
|
+
interface TouchInteraction {
|
|
2098
|
+
/** The interaction position on the screen */
|
|
2099
|
+
positionInViewport: Vector2;
|
|
2100
|
+
/** The area of the interaction represented as a radius of the ellipse */
|
|
2101
|
+
radius: Vector2;
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Contains the information about the touch screen interaction
|
|
2105
|
+
* @public
|
|
2106
|
+
* @category Input
|
|
2107
|
+
* @example
|
|
2108
|
+
* ```js
|
|
2109
|
+
* const touch = this.inputController.touch;
|
|
2110
|
+
*
|
|
2111
|
+
* if (touch.touching) {
|
|
2112
|
+
* const interaction = touch.interactions[0];
|
|
2113
|
+
* }
|
|
2114
|
+
* ```
|
|
2115
|
+
*/
|
|
2116
|
+
declare class TouchScreen {
|
|
2117
|
+
/**
|
|
2118
|
+
* TRUE if there is an interaction with the screen
|
|
2119
|
+
*/
|
|
2120
|
+
touching: boolean;
|
|
2121
|
+
/**
|
|
2122
|
+
* The information about the interactions with the screen
|
|
2123
|
+
*/
|
|
2124
|
+
interactions: TouchInteraction[];
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
declare class InputManager {
|
|
2128
|
+
readonly keyboard: Keyboard;
|
|
2129
|
+
readonly mouse: Mouse;
|
|
2130
|
+
readonly touchScreen: TouchScreen;
|
|
2131
|
+
readonly gamepads: GamepadController[];
|
|
2132
|
+
constructor();
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
/**
|
|
2136
|
+
* Manages the properties associated with time.
|
|
2137
|
+
* @public
|
|
2138
|
+
* @category Managers
|
|
2139
|
+
* @example
|
|
2140
|
+
* ```js
|
|
2141
|
+
* // using deltaTime to increment a timer
|
|
2142
|
+
* this.timer += this.timeManager.deltaTime;
|
|
2143
|
+
*
|
|
2144
|
+
* // using physicsDeltaTime within a physics component to move the object it belongs to
|
|
2145
|
+
* this.transform.position.x += speed * this.timeManager.physicsDeltaTime;
|
|
2146
|
+
*
|
|
2147
|
+
* // stop all time-related interactions by setting the scale to zero
|
|
2148
|
+
* this.timeManager.timeScale = 0;
|
|
2149
|
+
* ```
|
|
2150
|
+
*/
|
|
2151
|
+
declare class TimeManager {
|
|
2152
|
+
/** @internal */
|
|
2153
|
+
readonly fixedGameFramerate: number;
|
|
2154
|
+
/** @internal */
|
|
2155
|
+
readonly fixedGameDeltaTime: number;
|
|
2156
|
+
/** @internal */
|
|
2157
|
+
readonly fixedPhysicsFramerate: number;
|
|
2158
|
+
/** @internal */
|
|
2159
|
+
readonly fixedPhysicsDeltaTime: number;
|
|
2160
|
+
/**
|
|
2161
|
+
* The scale on which time passes. The default value is 1.\
|
|
2162
|
+
* For example, if set to 2, the time will run at twice the speed.\
|
|
2163
|
+
* If set to 0.5, it will run at half the speed.\
|
|
2164
|
+
* If set to 0, everything associated with the time will stop.
|
|
2165
|
+
*/
|
|
2166
|
+
timeScale: number;
|
|
2167
|
+
/** The time difference, in seconds, between the last frame of and the current frame recorded by the browser. */
|
|
2168
|
+
browserDeltaTime: number;
|
|
2169
|
+
/** The time difference, in seconds, between the last frame and the current frame, unaffected by the scale. */
|
|
2170
|
+
unscaledDeltaTime: number;
|
|
2171
|
+
/** The time difference, in seconds, between the last physics frame and the current one, unaffected by the scale. */
|
|
2172
|
+
unscaledPhysicsDeltaTime: number;
|
|
2173
|
+
private maxDeltaTime;
|
|
2174
|
+
private thenForGame;
|
|
2175
|
+
private thenForPhysics;
|
|
2176
|
+
private thenForRender;
|
|
2177
|
+
/** The time difference, in seconds, between the last frame and the current frame. */
|
|
2178
|
+
get deltaTime(): number;
|
|
2179
|
+
/** The time difference, in seconds, between the last physics frame and the current one. */
|
|
2180
|
+
get physicsDeltaTime(): number;
|
|
2181
|
+
/** The browser delta time affected by time scale. */
|
|
2182
|
+
get renderDeltaTime(): number;
|
|
2183
|
+
constructor({ physicsFramerate }: GameConfig);
|
|
2184
|
+
/** @internal */
|
|
2185
|
+
updateForRender(time: number): void;
|
|
2186
|
+
/** @internal */
|
|
2187
|
+
updateForGame(time: number): void;
|
|
2188
|
+
/** @internal */
|
|
2189
|
+
updateForPhysics(time: number): void;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
declare abstract class GameSystem implements System {
|
|
2193
|
+
protected readonly entityManager: EntityManager;
|
|
2194
|
+
protected readonly assetManager: AssetManager;
|
|
2195
|
+
protected readonly sceneManager: SceneManager;
|
|
2196
|
+
protected readonly timeManager: TimeManager;
|
|
2197
|
+
protected readonly inputManager: InputManager;
|
|
2198
|
+
protected readonly collisionRepository: CollisionRepository;
|
|
2199
|
+
onUpdate(): void;
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
declare function gameLogicSystem(): (target: SystemType) => void;
|
|
2203
|
+
declare function gamePhysicsSystem(): (target: SystemType) => void;
|
|
2204
|
+
declare function gamePreRenderSystem(): (target: SystemType) => void;
|
|
2205
|
+
|
|
2206
|
+
declare const Symbols: {
|
|
2207
|
+
AssetManager: symbol;
|
|
2208
|
+
CanvasElement: symbol;
|
|
2209
|
+
CollisionRepository: symbol;
|
|
2210
|
+
EntityManager: symbol;
|
|
2211
|
+
GameConfig: symbol;
|
|
2212
|
+
InputManager: symbol;
|
|
2213
|
+
SceneManager: symbol;
|
|
2214
|
+
SystemManager: symbol;
|
|
2215
|
+
TimeManager: symbol;
|
|
2216
|
+
};
|
|
2217
|
+
|
|
2218
|
+
export { Animation, type AnimationSlice, Animator, type AnimatorOptions, AssetManager, AudioPlayer, type AudioPlayerAction, type AudioPlayerOptions, BallCollider, type BallColliderOptions, BoxCollider, type BoxColliderOptions, BroadPhaseMethods, Button, type ButtonOptions, ButtonShape, Camera, type CameraOptions, Children, type Chunk, Circumference, type Collider, type Collision, type CollisionMatrix, CollisionMethods, CollisionRepository, type CollisionResolution, type Component, type ComponentType, EdgeCollider, type EdgeColliderOptions, type Entity, EntityManager, Game, type GameConfig, GameSystem, GamepadController, InputManager, Keyboard, type Light, LightRenderer, type LightRendererOptions, MaskRenderer, type MaskRendererOptions, MaskShape, Mouse, Parent, Polygon, PolygonCollider, type PolygonColliderOptions, Rectangle, RigidBody, type RigidBodyOptions, RigidBodyType, Scene, SceneManager, type SceneType, type SearchCriteria, type SearchResult, ShadowRenderer, type ShadowRendererOptions, type Shape, type Slice, SpriteRenderer, type SpriteRendererOptions, Symbols, type System, type SystemGroup, SystemManager, type SystemType, TextOrientation, TextRenderer, type TextRendererOptions, type TiledChunk, type TiledLayer, type TiledObject, type TiledObjectLayer, type TiledProperty, type TiledTilemap, TiledWrapper, type TiledWrapperOptions, TilemapCollider, type TilemapColliderOptions, TilemapOrientation, TilemapRenderer, type TilemapRendererOptions, type Tileset, TimeManager, type TouchInteraction, TouchScreen, Transform, type TransformOptions, Vector2, type VibrationInput, VideoRenderer, type VideoRendererOptions, between, clamp, defaultRenderLayer, fixedRound, gameLogicSystem, gamePhysicsSystem, gamePreRenderSystem, inject, injectable, randomFloat, randomInt, range };
|