littlejsengine 1.11.9 → 1.11.13
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 +3 -3
- package/dist/littlejs.d.ts +485 -492
- package/dist/littlejs.esm.js +548 -529
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +546 -525
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +502 -484
- package/examples/htmlMenu/game.js +11 -1
- package/examples/htmlMenu/index.html +1 -10
- package/examples/module/game.js +2 -2
- package/examples/shorts/base.html +1 -1
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/build.js +13 -3
- package/examples/starter/game.js +8 -1
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +102 -0
- package/examples/typescript/build.bat +5 -0
- package/examples/typescript/build.js +33 -0
- package/examples/typescript/game.js +102 -0
- package/examples/typescript/game.ts +134 -0
- package/examples/typescript/index.html +10 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +8 -0
- package/package.json +1 -1
- package/plugins/newgrounds.js +44 -35
- package/plugins/postProcess.js +18 -4
- package/plugins/uiSystem.js +196 -30
- package/src/engine.js +21 -20
- package/src/engineAudio.js +59 -59
- package/src/engineDebug.js +44 -41
- package/src/engineDraw.js +58 -58
- package/src/engineExport.js +2 -4
- package/src/engineInput.js +40 -35
- package/src/engineMedals.js +21 -11
- package/src/engineObject.js +42 -35
- package/src/engineParticles.js +10 -10
- package/src/engineSettings.js +77 -82
- package/src/engineTileLayer.js +21 -21
- package/src/engineUtilities.js +150 -150
- package/src/engineWebGL.js +3 -3
package/plugins/uiSystem.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - Buttons
|
|
6
6
|
* - Checkboxes
|
|
7
7
|
* - Images
|
|
8
|
+
* @namespace UISystemPlugin
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
'use strict';
|
|
@@ -12,18 +13,55 @@
|
|
|
12
13
|
///////////////////////////////////////////////////////////////////////////////
|
|
13
14
|
|
|
14
15
|
// ui defaults
|
|
16
|
+
|
|
17
|
+
/** Default fill color for UI elements
|
|
18
|
+
* @type {Color}
|
|
19
|
+
* @memberof UISystemPlugin */
|
|
15
20
|
let uiDefaultColor = WHITE;
|
|
21
|
+
|
|
22
|
+
/** Default outline color for UI elements
|
|
23
|
+
* @type {Color}
|
|
24
|
+
* @memberof UISystemPlugin */
|
|
16
25
|
let uiDefaultLineColor = BLACK;
|
|
26
|
+
|
|
27
|
+
/** Default text color for UI elements
|
|
28
|
+
* @type {Color}
|
|
29
|
+
* @memberof UISystemPlugin */
|
|
17
30
|
let uiDefaultTextColor = BLACK;
|
|
31
|
+
|
|
32
|
+
/** Default button color for UI elements
|
|
33
|
+
* @type {Color}
|
|
34
|
+
* @memberof UISystemPlugin */
|
|
18
35
|
let uiDefaultButtonColor = hsl(0,0,.5);
|
|
36
|
+
|
|
37
|
+
/** Default hover color for UI elements
|
|
38
|
+
* @type {Color}
|
|
39
|
+
* @memberof UISystemPlugin */
|
|
19
40
|
let uiDefaultHoverColor = hsl(0,0,.7);
|
|
20
|
-
let uiDefaultLineWidth = 4;
|
|
21
|
-
let uiDefaultFont = 'arial';
|
|
22
41
|
|
|
23
|
-
|
|
42
|
+
/** Default line width for UI elements
|
|
43
|
+
* @type {number}
|
|
44
|
+
* @memberof UISystemPlugin */
|
|
45
|
+
let uiDefaultLineWidth = 4;
|
|
46
|
+
|
|
47
|
+
/** Default font for UI elements
|
|
48
|
+
* @type {string}
|
|
49
|
+
* @memberof UISystemPlugin */
|
|
50
|
+
let uiDefaultFont = 'arial';
|
|
51
|
+
|
|
52
|
+
/** List of all UI elements
|
|
53
|
+
* @type {Array<UIObject>}
|
|
54
|
+
* @memberof UISystemPlugin */
|
|
24
55
|
let uiObjects = [];
|
|
56
|
+
|
|
57
|
+
/** Context to render UI elements to
|
|
58
|
+
* @type {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D}
|
|
59
|
+
* @memberof UISystemPlugin */
|
|
25
60
|
let uiContext;
|
|
26
61
|
|
|
62
|
+
/** Set up the UI system, typically called in gameInit
|
|
63
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
64
|
+
* @memberof UISystemPlugin */
|
|
27
65
|
function initUISystem(context=overlayContext)
|
|
28
66
|
{
|
|
29
67
|
uiContext = context;
|
|
@@ -60,6 +98,13 @@ function initUISystem(context=overlayContext)
|
|
|
60
98
|
}
|
|
61
99
|
}
|
|
62
100
|
|
|
101
|
+
/** Draw a rectangle to the UI context
|
|
102
|
+
* @param {Vector2} pos
|
|
103
|
+
* @param {Vector2} size
|
|
104
|
+
* @param {Color} [color=uiDefaultColor]
|
|
105
|
+
* @param {number} [lineWidth=uiDefaultLineWidth]
|
|
106
|
+
* @param {Color} [lineColor=uiDefaultLineColor]
|
|
107
|
+
* @memberof UISystemPlugin */
|
|
63
108
|
function drawUIRect(pos, size, color=uiDefaultColor, lineWidth=uiDefaultLineWidth, lineColor=uiDefaultLineColor)
|
|
64
109
|
{
|
|
65
110
|
uiContext.fillStyle = color.toString();
|
|
@@ -74,47 +119,92 @@ function drawUIRect(pos, size, color=uiDefaultColor, lineWidth=uiDefaultLineWidt
|
|
|
74
119
|
}
|
|
75
120
|
}
|
|
76
121
|
|
|
77
|
-
|
|
122
|
+
/** Draw a line to the UI context
|
|
123
|
+
* @param {Vector2} posA
|
|
124
|
+
* @param {Vector2} posB
|
|
125
|
+
* @param {number} [lineWidth=uiDefaultLineWidth]
|
|
126
|
+
* @param {Color} [lineColor=uiDefaultLineColor]
|
|
127
|
+
* @memberof UISystemPlugin */
|
|
128
|
+
function drawUILine(posA, posB, lineWidth=uiDefaultLineWidth, lineColor=uiDefaultLineColor)
|
|
78
129
|
{
|
|
79
|
-
uiContext.strokeStyle =
|
|
80
|
-
uiContext.lineWidth =
|
|
130
|
+
uiContext.strokeStyle = lineColor.toString();
|
|
131
|
+
uiContext.lineWidth = lineWidth;
|
|
81
132
|
uiContext.beginPath();
|
|
82
133
|
uiContext.lineTo(posA.x, posA.y);
|
|
83
134
|
uiContext.lineTo(posB.x, posB.y);
|
|
84
135
|
uiContext.stroke();
|
|
85
136
|
}
|
|
86
137
|
|
|
138
|
+
/** Draw a tile to the UI context
|
|
139
|
+
* @param {Vector2} pos
|
|
140
|
+
* @param {Vector2} size
|
|
141
|
+
* @param {TileInfo} tileInfo
|
|
142
|
+
* @param {Color} [color=uiDefaultColor]
|
|
143
|
+
* @param {number} [angle]
|
|
144
|
+
* @param {boolean} [mirror]
|
|
145
|
+
* @memberof UISystemPlugin */
|
|
87
146
|
function drawUITile(pos, size, tileInfo, color=uiDefaultColor, angle=0, mirror=false)
|
|
88
147
|
{
|
|
89
148
|
drawTile(pos, size, tileInfo, color, angle, mirror, BLACK, false, true, uiContext);
|
|
90
149
|
}
|
|
91
150
|
|
|
151
|
+
/** Draw text to the UI context
|
|
152
|
+
* @param {string} text
|
|
153
|
+
* @param {Vector2} pos
|
|
154
|
+
* @param {Vector2} size
|
|
155
|
+
* @param {Color} [color=uiDefaultColor]
|
|
156
|
+
* @param {number} [lineWidth=uiDefaultLineWidth]
|
|
157
|
+
* @param {Color} [lineColor=uiDefaultLineColor]
|
|
158
|
+
* @param {string} [align]
|
|
159
|
+
* @param {string} [font=uiDefaultFont]
|
|
160
|
+
* @memberof UISystemPlugin */
|
|
92
161
|
function drawUIText(text, pos, size, color=uiDefaultColor, lineWidth=uiDefaultLineWidth, lineColor=uiDefaultLineColor, align='center', font=uiDefaultFont)
|
|
93
162
|
{
|
|
94
163
|
drawTextScreen(text, pos, size.y, color, lineWidth, lineColor, align, font, size.x, uiContext);
|
|
95
164
|
}
|
|
96
165
|
|
|
97
166
|
///////////////////////////////////////////////////////////////////////////////
|
|
98
|
-
|
|
167
|
+
/**
|
|
168
|
+
* UI Object - Base level object for all UI elements
|
|
169
|
+
*/
|
|
99
170
|
class UIObject
|
|
100
171
|
{
|
|
101
|
-
|
|
172
|
+
/** Create a UIObject
|
|
173
|
+
* @param {Vector2} [pos=(0,0)]
|
|
174
|
+
* @param {Vector2} [size=(1,1)]
|
|
175
|
+
*/
|
|
176
|
+
constructor(pos=vec2(), size=vec2())
|
|
102
177
|
{
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
178
|
+
/** @property {Vector2} - Local position of the object */
|
|
179
|
+
this.localPos = pos.copy();
|
|
180
|
+
/** @property {Vector2} - Screen space position of the object */
|
|
181
|
+
this.pos = pos.copy();
|
|
182
|
+
/** @property {Vector2} - Screen space size of the object */
|
|
183
|
+
this.size = size.copy();
|
|
184
|
+
/** @property {Color} */
|
|
106
185
|
this.color = uiDefaultColor;
|
|
186
|
+
/** @property {Color} */
|
|
107
187
|
this.lineColor = uiDefaultLineColor;
|
|
188
|
+
/** @property {Color} */
|
|
108
189
|
this.textColor = uiDefaultTextColor;
|
|
190
|
+
/** @property {Color} */
|
|
109
191
|
this.hoverColor = uiDefaultHoverColor;
|
|
192
|
+
/** @property {number} */
|
|
110
193
|
this.lineWidth = uiDefaultLineWidth;
|
|
194
|
+
/** @property {string} */
|
|
111
195
|
this.font = uiDefaultFont;
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
196
|
+
/** @property {boolean} */
|
|
197
|
+
this.visible = true;
|
|
198
|
+
/** @property {Array<UIObject>} */
|
|
199
|
+
this.children = [];
|
|
200
|
+
/** @property {UIObject} */
|
|
201
|
+
this.parent = undefined;
|
|
115
202
|
uiObjects.push(this);
|
|
116
203
|
}
|
|
117
204
|
|
|
205
|
+
/** Add a child UIObject to this object
|
|
206
|
+
* @param {UIObject} child
|
|
207
|
+
*/
|
|
118
208
|
addChild(child)
|
|
119
209
|
{
|
|
120
210
|
ASSERT(!child.parent && !this.children.includes(child));
|
|
@@ -122,13 +212,17 @@ class UIObject
|
|
|
122
212
|
child.parent = this;
|
|
123
213
|
}
|
|
124
214
|
|
|
215
|
+
/** Remove a child UIObject from this object
|
|
216
|
+
* @param {UIObject} child
|
|
217
|
+
*/
|
|
125
218
|
removeChild(child)
|
|
126
219
|
{
|
|
127
220
|
ASSERT(child.parent == this && this.children.includes(child));
|
|
128
221
|
this.children.splice(this.children.indexOf(child), 1);
|
|
129
|
-
child.parent =
|
|
222
|
+
child.parent = undefined;
|
|
130
223
|
}
|
|
131
224
|
|
|
225
|
+
/** Update the object, called automatically by plugin once each frame */
|
|
132
226
|
update()
|
|
133
227
|
{
|
|
134
228
|
// track mouse input
|
|
@@ -157,32 +251,55 @@ class UIObject
|
|
|
157
251
|
this.onRelease();
|
|
158
252
|
}
|
|
159
253
|
}
|
|
254
|
+
|
|
255
|
+
/** Render the object, called automatically by plugin once each frame */
|
|
160
256
|
render()
|
|
161
257
|
{
|
|
162
258
|
if (this.size.x && this.size.y)
|
|
163
259
|
drawUIRect(this.pos, this.size, this.color, this.lineWidth, this.lineColor);
|
|
164
260
|
}
|
|
165
261
|
|
|
166
|
-
|
|
262
|
+
/** Called when the mouse enters the object */
|
|
167
263
|
onEnter() {}
|
|
264
|
+
|
|
265
|
+
/** Called when the mouse leaves the object */
|
|
168
266
|
onLeave() {}
|
|
267
|
+
|
|
268
|
+
/** Called when the mouse is pressed while over the object */
|
|
169
269
|
onPress() {}
|
|
270
|
+
|
|
271
|
+
/** Called when the mouse is released while over the object */
|
|
170
272
|
onRelease() {}
|
|
273
|
+
|
|
274
|
+
/** Called when the state of this object changes */
|
|
171
275
|
onChange() {}
|
|
172
276
|
}
|
|
173
277
|
|
|
174
278
|
///////////////////////////////////////////////////////////////////////////////
|
|
175
|
-
|
|
279
|
+
/**
|
|
280
|
+
* UIText - A UI object that displays text
|
|
281
|
+
* @extends UIObject
|
|
282
|
+
*/
|
|
176
283
|
class UIText extends UIObject
|
|
177
284
|
{
|
|
178
|
-
|
|
285
|
+
/** Create a UIText object
|
|
286
|
+
* @param {Vector2} [pos]
|
|
287
|
+
* @param {Vector2} [size]
|
|
288
|
+
* @param {string} [text]
|
|
289
|
+
* @param {string} [align]
|
|
290
|
+
* @param {string} [font=uiDefaultFont]
|
|
291
|
+
*/
|
|
292
|
+
constructor(pos, size, text='', align='center', font=uiDefaultFont)
|
|
179
293
|
{
|
|
180
294
|
super(pos, size);
|
|
181
295
|
|
|
296
|
+
/** @property {string} */
|
|
182
297
|
this.text = text;
|
|
298
|
+
/** @property {string} */
|
|
183
299
|
this.align = align;
|
|
184
|
-
|
|
185
|
-
this.
|
|
300
|
+
|
|
301
|
+
this.font = font; // set font
|
|
302
|
+
this.lineWidth = 0; // set text to not be outlined by default
|
|
186
303
|
}
|
|
187
304
|
render()
|
|
188
305
|
{
|
|
@@ -191,17 +308,31 @@ class UIText extends UIObject
|
|
|
191
308
|
}
|
|
192
309
|
|
|
193
310
|
///////////////////////////////////////////////////////////////////////////////
|
|
194
|
-
|
|
311
|
+
/**
|
|
312
|
+
* UITile - A UI object that displays a tile image
|
|
313
|
+
* @extends UIObject
|
|
314
|
+
*/
|
|
195
315
|
class UITile extends UIObject
|
|
196
316
|
{
|
|
317
|
+
/** Create a UITile object
|
|
318
|
+
* @param {Vector2} [pos]
|
|
319
|
+
* @param {Vector2} [size]
|
|
320
|
+
* @param {TileInfo} [tileInfo]
|
|
321
|
+
* @param {Color} [color=WHITE]
|
|
322
|
+
* @param {number} [angle]
|
|
323
|
+
* @param {boolean} [mirror]
|
|
324
|
+
*/
|
|
197
325
|
constructor(pos, size, tileInfo, color=WHITE, angle=0, mirror=false)
|
|
198
326
|
{
|
|
199
327
|
super(pos, size);
|
|
200
328
|
|
|
329
|
+
/** @property {TileInfo} - Tile image to use */
|
|
201
330
|
this.tileInfo = tileInfo;
|
|
202
|
-
|
|
331
|
+
/** @property {number} - Angle to rotate in radians */
|
|
203
332
|
this.angle = angle;
|
|
333
|
+
/** @property {boolean} - Should it be mirrored? */
|
|
204
334
|
this.mirror = mirror;
|
|
335
|
+
this.color = color;
|
|
205
336
|
}
|
|
206
337
|
render()
|
|
207
338
|
{
|
|
@@ -210,14 +341,25 @@ class UITile extends UIObject
|
|
|
210
341
|
}
|
|
211
342
|
|
|
212
343
|
///////////////////////////////////////////////////////////////////////////////
|
|
213
|
-
|
|
344
|
+
/**
|
|
345
|
+
* UIButton - A UI object that acts as a button
|
|
346
|
+
* @extends UIObject
|
|
347
|
+
*/
|
|
214
348
|
class UIButton extends UIObject
|
|
215
349
|
{
|
|
216
|
-
|
|
350
|
+
/** Create a UIButton object
|
|
351
|
+
* @param {Vector2} [pos]
|
|
352
|
+
* @param {Vector2} [size]
|
|
353
|
+
* @param {string} [text]
|
|
354
|
+
* @param {Color} [color=uiDefaultButtonColor]
|
|
355
|
+
*/
|
|
356
|
+
constructor(pos, size, text, color=uiDefaultButtonColor)
|
|
217
357
|
{
|
|
218
358
|
super(pos, size);
|
|
359
|
+
|
|
360
|
+
/** @property {string} */
|
|
219
361
|
this.text = text;
|
|
220
|
-
this.color =
|
|
362
|
+
this.color = color;
|
|
221
363
|
}
|
|
222
364
|
render()
|
|
223
365
|
{
|
|
@@ -231,12 +373,22 @@ class UIButton extends UIObject
|
|
|
231
373
|
}
|
|
232
374
|
|
|
233
375
|
///////////////////////////////////////////////////////////////////////////////
|
|
234
|
-
|
|
376
|
+
/**
|
|
377
|
+
* UICheckbox - A UI object that acts as a checkbox
|
|
378
|
+
* @extends UIObject
|
|
379
|
+
*/
|
|
235
380
|
class UICheckbox extends UIObject
|
|
236
381
|
{
|
|
382
|
+
/** Create a UICheckbox object
|
|
383
|
+
* @param {Vector2} [pos]
|
|
384
|
+
* @param {Vector2} [size]
|
|
385
|
+
* @param {boolean} [checked]
|
|
386
|
+
*/
|
|
237
387
|
constructor(pos, size, checked=false)
|
|
238
388
|
{
|
|
239
389
|
super(pos, size);
|
|
390
|
+
|
|
391
|
+
/** @property {boolean} */
|
|
240
392
|
this.checked = checked;
|
|
241
393
|
}
|
|
242
394
|
onPress()
|
|
@@ -258,16 +410,30 @@ class UICheckbox extends UIObject
|
|
|
258
410
|
}
|
|
259
411
|
|
|
260
412
|
///////////////////////////////////////////////////////////////////////////////
|
|
261
|
-
|
|
413
|
+
/**
|
|
414
|
+
* UIScrollbar - A UI object that acts as a scrollbar
|
|
415
|
+
* @extends UIObject
|
|
416
|
+
*/
|
|
262
417
|
class UIScrollbar extends UIObject
|
|
263
418
|
{
|
|
264
|
-
|
|
419
|
+
/** Create a UIScrollbar object
|
|
420
|
+
* @param {Vector2} [pos]
|
|
421
|
+
* @param {Vector2} [size]
|
|
422
|
+
* @param {number} [value]
|
|
423
|
+
* @param {string} [text]
|
|
424
|
+
* @param {Color} [color=uiDefaultButtonColor]
|
|
425
|
+
* @param {Color} [handleColor=WHITE]
|
|
426
|
+
*/
|
|
427
|
+
constructor(pos, size, value=.5, text='', color=uiDefaultButtonColor, handleColor=WHITE)
|
|
265
428
|
{
|
|
266
429
|
super(pos, size);
|
|
430
|
+
|
|
431
|
+
/** @property {number} */
|
|
267
432
|
this.value = value;
|
|
433
|
+
/** @property {string} */
|
|
268
434
|
this.text = text;
|
|
269
|
-
this.color =
|
|
270
|
-
this.handleColor =
|
|
435
|
+
this.color = color;
|
|
436
|
+
this.handleColor = handleColor;
|
|
271
437
|
}
|
|
272
438
|
update()
|
|
273
439
|
{
|
package/src/engine.js
CHANGED
|
@@ -21,61 +21,62 @@
|
|
|
21
21
|
'use strict';
|
|
22
22
|
|
|
23
23
|
/** Name of engine
|
|
24
|
-
* @type {
|
|
24
|
+
* @type {string}
|
|
25
25
|
* @default
|
|
26
26
|
* @memberof Engine */
|
|
27
27
|
const engineName = 'LittleJS';
|
|
28
28
|
|
|
29
29
|
/** Version of engine
|
|
30
|
-
* @type {
|
|
30
|
+
* @type {string}
|
|
31
31
|
* @default
|
|
32
32
|
* @memberof Engine */
|
|
33
|
-
const engineVersion = '1.11.
|
|
33
|
+
const engineVersion = '1.11.13';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {number}
|
|
37
37
|
* @default
|
|
38
38
|
* @memberof Engine */
|
|
39
39
|
const frameRate = 60;
|
|
40
40
|
|
|
41
41
|
/** How many seconds each frame lasts, engine uses a fixed time step
|
|
42
|
-
* @type {
|
|
42
|
+
* @type {number}
|
|
43
43
|
* @default 1/60
|
|
44
44
|
* @memberof Engine */
|
|
45
45
|
const timeDelta = 1/frameRate;
|
|
46
46
|
|
|
47
47
|
/** Array containing all engine objects
|
|
48
|
-
* @type {Array}
|
|
48
|
+
* @type {Array<EngineObject>}
|
|
49
49
|
* @memberof Engine */
|
|
50
50
|
let engineObjects = [];
|
|
51
51
|
|
|
52
52
|
/** Array with only objects set to collide with other objects this frame (for optimization)
|
|
53
|
-
* @type {Array}
|
|
53
|
+
* @type {Array<EngineObject>}
|
|
54
54
|
* @memberof Engine */
|
|
55
55
|
let engineObjectsCollide = [];
|
|
56
56
|
|
|
57
57
|
/** Current update frame, used to calculate time
|
|
58
|
-
* @type {
|
|
58
|
+
* @type {number}
|
|
59
59
|
* @memberof Engine */
|
|
60
60
|
let frame = 0;
|
|
61
61
|
|
|
62
62
|
/** Current engine time since start in seconds
|
|
63
|
-
* @type {
|
|
63
|
+
* @type {number}
|
|
64
64
|
* @memberof Engine */
|
|
65
65
|
let time = 0;
|
|
66
66
|
|
|
67
67
|
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
68
|
-
* @type {
|
|
68
|
+
* @type {number}
|
|
69
69
|
* @memberof Engine */
|
|
70
70
|
let timeReal = 0;
|
|
71
71
|
|
|
72
72
|
/** Is the game paused? Causes time and objects to not be updated
|
|
73
|
-
* @type {
|
|
73
|
+
* @type {boolean}
|
|
74
74
|
* @default false
|
|
75
75
|
* @memberof Engine */
|
|
76
76
|
let paused = false;
|
|
77
|
+
|
|
77
78
|
/** Set if game is paused
|
|
78
|
-
* @param {
|
|
79
|
+
* @param {boolean} isPaused
|
|
79
80
|
* @memberof Engine */
|
|
80
81
|
function setPaused(isPaused) { paused = isPaused; }
|
|
81
82
|
|
|
@@ -108,7 +109,7 @@ function engineAddPlugin(updateFunction, renderFunction)
|
|
|
108
109
|
* @param {Function} gameUpdatePost - Called after physics and objects are updated, even when paused
|
|
109
110
|
* @param {Function} gameRender - Called before objects are rendered, for drawing the background
|
|
110
111
|
* @param {Function} gameRenderPost - Called after objects are rendered, useful for drawing UI
|
|
111
|
-
* @param {Array} [imageSources=[]] - List of images to load
|
|
112
|
+
* @param {Array<string>} [imageSources=[]] - List of images to load
|
|
112
113
|
* @param {HTMLElement} [rootElement] - Root element to attach to, the document body by default
|
|
113
114
|
* @memberof Engine */
|
|
114
115
|
function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSources=[], rootElement=document.body)
|
|
@@ -404,9 +405,9 @@ function engineObjectsDestroy()
|
|
|
404
405
|
|
|
405
406
|
/** Collects all object within a given area
|
|
406
407
|
* @param {Vector2} [pos] - Center of test area, or undefined for all objects
|
|
407
|
-
* @param {
|
|
408
|
-
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
409
|
-
* @return {Array} - List of collected objects
|
|
408
|
+
* @param {Vector2|number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
409
|
+
* @param {Array<EngineObject>} [objects=engineObjects] - List of objects to check
|
|
410
|
+
* @return {Array<EngineObject>} - List of collected objects
|
|
410
411
|
* @memberof Engine */
|
|
411
412
|
function engineObjectsCollect(pos, size, objects=engineObjects)
|
|
412
413
|
{
|
|
@@ -432,9 +433,9 @@ function engineObjectsCollect(pos, size, objects=engineObjects)
|
|
|
432
433
|
|
|
433
434
|
/** Triggers a callback for each object within a given area
|
|
434
435
|
* @param {Vector2} [pos] - Center of test area, or undefined for all objects
|
|
435
|
-
* @param {
|
|
436
|
+
* @param {Vector2|number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
436
437
|
* @param {Function} [callbackFunction] - Calls this function on every object that passes the test
|
|
437
|
-
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
438
|
+
* @param {Array<EngineObject>} [objects=engineObjects] - List of objects to check
|
|
438
439
|
* @memberof Engine */
|
|
439
440
|
function engineObjectsCallback(pos, size, callbackFunction, objects=engineObjects)
|
|
440
441
|
{ engineObjectsCollect(pos, size, objects).forEach(o => callbackFunction(o)); }
|
|
@@ -442,8 +443,8 @@ function engineObjectsCallback(pos, size, callbackFunction, objects=engineObject
|
|
|
442
443
|
/** Return a list of objects intersecting a ray
|
|
443
444
|
* @param {Vector2} start
|
|
444
445
|
* @param {Vector2} end
|
|
445
|
-
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
446
|
-
* @return {Array} - List of objects hit
|
|
446
|
+
* @param {Array<EngineObject>} [objects=engineObjects] - List of objects to check
|
|
447
|
+
* @return {Array<EngineObject>} - List of objects hit
|
|
447
448
|
* @memberof Engine */
|
|
448
449
|
function engineObjectsRaycast(start, end, objects=engineObjects)
|
|
449
450
|
{
|